- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 2
- Posts with Upvotes
- 2
- Upvoting Members
- 2
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
73 Posted Topics
Re: Or, sort a list of class objects by an attribute (similar idea as above): [CODE=python]import operator import string def normcaps(strg): s = string.upper(strg[0]) + strg[1:] return s class Man: def __init__(self,name,pos,age): self.name = name.lower() self.pos = pos.lower() self.age = age def __getitem__(self,key): return self.__dict__[key] def __repr__(self): return self.__str__() def __str__(self): … | |
Re: Also, you might want to make sure you are always dealing withe floats: [CODE=python]>>> float(499.99) 499.99000000000001 >>> float(500) - float(499.99) 0.0099999999999909051 >>> round(float(500) - float(499.99),2) 0.01 >>> type(499.99) <type 'float'> >>> type(500) <type 'int'>[/CODE] And round is definitely a must. | |
There seems to be a variety of ways to do this on the net, does anybody have a tested solution? Suggestions to look at various modules and such appreciated. I don't need the full code. | |
Re: This is lame! Is there a better free IDE? I'm sick of IDLE's issues. | |
Re: Heh heh, I love eclipse, but the interactive shell (a la IDLE) is pretty darn awesome for testing stuff out. Example: [CODE=python]>>> #start with your function >>> def count_chars(char,string): """A functiont that counts how many chars in the string""" pass >>> strg = 'bunnies' >>> count_chars('n',strg) #nothing happens! >>> def … | |
Re: From what you've said, it sounds like you have to print out elements 3 through 6 (if 0 is the first element) of a list. This will print those 4 elements, doesn't matter how long the list is. [CODE=python]n = 3 while n <= 6: print lst[n] n += 1 … | |
Re: I would suggest that instead of storing the data in separate lists, store all the data in a class. example: [CODE=python]class Data: def __init__(self,row,value,var1,var2): self.row = row self.value = value self.var1 = var1 self.var2 = var2 [/CODE] Call this for each row of data, put all of the classes in … | |
Hi all, Here's my issue: [CODE=python]>>> a = [1,2,3] #all good so far >>> b = a #make a copy of a, called b >>> b.remove(1) #remove value 1 from b ONLY >>> print a #grrr, value has also been removed from a [2, 3] >>> print b #and b! … | |
| |
Re: More info, plz. State clearly what you are trying to to. Are you going to try and use python to parse the results (via html scrape)? Because that would likely mean regular expressions and that would be tough. | |
Re: Should be noted that Python won't mutate your string. If you say [ICODE]s = "'Quote Example'\tby person\n"[/ICODE] s will always be that string unless you reassign it. When you print it, python interprets the '\t's to be tabs, but s is still the same. | |
Hi all, I'm trying to mimic an html form that calls a script on the web. When I put the form together on a page, it works, and I was wondering if there was a way I could "scrape" this post request and see what I'm missing when I try … | |
Hey all, Here's my problem: I have a class that I want to be able to save and and load. But I need the class to be mutable I guess. Check it out: [CODE=python]class Tool: def __init__(self,name,function): self.name = name self.function = function self.savename = self.name + '.txt' def save(self): … | |
Re: Whenever I start a script I usually write out in plain English what I want to do. It will keep you organized and you will never not know "where to start." Comment out the plain english, and script around it. For example, here is the "skeleton" for a script to … | |
Re: [QUOTE=leanne86;934802]That's the problem, I don't know where I can find the pstats code. I was just given the link and asked to fix it. Normally if it was something like [url]www.mycompany.com.au/files/something.html[/url] - I would know to log on to my website then go to the folder files and then edit … | |
Re: Your code looks somewhat roundabout. Quick sanity check, make the Label this and see if it works: [CODE=python]label = Label(parent,text = 'Hi world!',background = 'yellow')[/CODE] If theres a highlighted piece of text ('Hi World') your label works and it's an issue with displaying the image. Whenever I do anything, I … | |
Re: Stick both canvases in a mainframe, and attach the scrollbar to the mainframe. | |
Re: Neither am I. Interacting with mail servers like yahoo and gmail is unfortuanaetly not as simple as: connect, login, email. See below for what I use, but you may need to experiment with yahoo. The basic flow is connect, say hi,encryt, say hi (all secret like), log in, mail stuff. … | |
Re: What is the obsession with global variables? Seriously. Pass the necessary elements to your function, and return them back. You seem to be doing half of this, but you are not putting your return variables into anything. as in: [CODE=python]checkLimb(armRight) #bad, your return value isn't put into anything.[/CODE] This is … | |
Re: I would say it depends on your server configuration. Python has a MySQLdb module that lets it interact easily with MySQL databases (you would likely have to install it), but I'm not totally sure in terms of other databases. I'm becoming a bigger fan of php for websites to be … | |
Hey all, Working on a medium sized Tkinter app. I have it working fine, but I feel like the app isn't as clean as I would like it to be, namely because I have a million labels and different widgets and I can't figure out what to call them... For … | |
Re: [url]http://www.google.com/search?q=flash+command+line+arguments[/url] Welcome to the interwebs. Use 'em. | |
Hey all, Here's my problem: php/mysql noob here. I have an admin section on the website, and I have successfully password protected all the php pages in that directory using sessions. I have included code like this on the top of each of my pages: [code=php]<?php include('login.php'); if (checkLogin() != … | |
Re: How's this for a solution: Instead of worrying about what email client your users are using, have python send the email for them, through an account that you set up! It's fairly easy to get python to send email if you have an email account with smtp. Your GUI would … | |
Re: You should really check out the tutorial on python.org. Anyway, since you're having trouble wrapping your head around try except, here's a basic outline that handles bad choice slightly differently [CODE=python]#a simple class for our user class Player: def __init__(self,name): self.day = 0 self.name = name def __str__(self): s = … | |
Re: Okay, I quickly glanced over your code. It doesn't look like it works at all. Am I right? Note that subprocess.Popen only creates the instance, it doesn't run the command line. You need to use the methods communicate() or poll(). Once you get your command line to run, the python … | |
Re: This sounds awesome, but it also sounds like an API would be useful here. If you have the API (not sure if one exists) for MSN/YAHOO then I think that's where you should start. If you post a link to the API here that would be pretty neat too. | |
![]() | Re: Link directly to it. ie: somesite.com/myscript.py But make sure your print statements are "html" ie: print "<P> Hello shadowickman </p> " There are certain rules you have to follow for cgi scripts, they are mentioned earlier in this thread. I definitely recommend python for web development if you have been … ![]() |
Re: This thread makes my head hurt. Do you need to store all the info about the cars in a python module? What about a csv? Also, if you're going to call a class in a module, that class has to be part of the module if you're not doing it … | |
Re: Hey there, The short answer is that you haven't looked hard enough. ;) I realize that you probably don't want to hear that, so here's a quick and dirty explanation. Most sites don't like computers logging themselves into their protected areas. For this reason, they have created security to check … | |
Re: Mmkay. The first step is determining what your input and output are. I believe the input is the cheques.data file, and your output is the XHTML that looks something like this: [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>All Cheques</title> <style type="text/css"> td.amount { … | |
Re: Or you could just read up on the behavior of the canvas widget. Honestly doesn't really sound like you need the canvas. Labels and Text widgets should do it. | |
![]() | Re: lol dude, because subprocess.call takes a list as it's first arg! [CODE=python]filename = 'song.mp3' myList = ['myprog.exe',filename] subprocess.call(myList)[/CODE] Definetly look up the subprocess module, there's a whole lot more you can pass to call() that will help you direct your output, etcetera. You may want to look into the Popen … |
Re: Shameless promotion: [url]http://www.nudebeachfilms.org[/url] I use bluehost.com to host the site, and I put all sorts of other junk on it too, because as far as I can tell it's unlimited. Also unlimited subdirectories. But I pay for it. And as many of you know, you have to pay up front … | |
Re: Are you making a game? If you have a variable Gold and you want to add 200 to it (I'm assuming the player just got off work), why not just say: [icode=python]Gold = Gold + 200[/icode] Too easy? Or get fancy, say you have another variable called job: [CODE=python]def get_pay(job): … | |
Re: I haven't found the smtplib module to be super reliable, but here's what I use to send email: [CODE=python]def email(usertuple,sender,to,subject,msg): """Sends an email from a gmail account""" (login,pswd) = usertuple print 'Connecting...' mailServer = smtplib.SMTP("smtp.gmail.com", 0) print 'Initiating relationship...' mailServer.ehlo() print 'Encrypting...' mailServer.starttls() print 'Initiating encrypted relationship...' mailServer.ehlo() print 'Logging … | |
Re: you code confuse me too. Note this: [CODE=python]>>> range(11,12) [11] >>> for i in range(11,12): print i 11 [/CODE] You're only executing your first loop for when r = 11, ie 1 time only. Give us a little more code and some context. But yeah, no need for a loop … | |
Re: Not really recommended, since you don't really always want to pause your code but I think you want this: [CODE=python]class Name: def __init__(self): self.name = raw_input("Name: ")[/CODE] However, I'd have to agree that snippsat's solution is a better written class, because if neccessary you could use it on names that … | |
Re: code executes line by line, so with your code the label won't update until dosomething(x) is complete. Your dosomething function should theoretically call a callback everytime it finishes a block. urllib.urlretrieve sends a callback after every block for example. Since I'm assuming you wrote your own function, maybe this would … | |
Re: [QUOTE=sneekula;921987]Here is a Python output with an image: [code=python]# draw a flower with module turtle import turtle as tu tu.title('I call this one Flower') [/code] heh heh, that's awesome. The doc page for the turtle module: [url]http://docs.python.org/library/turtle.html[/url] My C++ teacher had made a similar thing for Beginning programming called "Athlete" | |
Re: Hey, I had a similar issue. I believe the easiest answer is to create a shared pylib and put your module in that folder. It's not wise to have multiple copies of modules, because when you change one, you end up having to change them all. So, have all your … | |
Re: You sounds like you've got it together, so the simple explanation is: -Google shutil.copytree. -Modify. -Execute. :) If you want a complete solution I can talk more about this, but I figured you might just want a poke in the right direction. os.walk is useful, but kinda tough to bend … | |
![]() | Re: Dude. Come on. You've posted in like 3 different threads about this very thing: [url]http://www.daniweb.com/forums/thread203590.html[/url] Search the string you get from the user for 'why.' There are several solutions in the linked thread. |
Re: If you chose tkinter: [url]http://effbot.org/tkinterbook/[/url] | |
Re: count() will return the number of [B]non-overlapping[/B] instances. See this page: [url]http://docs.python.org/library/string.html[/url] I wrote a function a while back to find all occurrences of x in a larger string. The idea is that you step along the string looking at snippets the size of the word you are trying to … | |
Re: Pop your log file open before you get the current ip and parse out the most recent ip logged. Then compare it with the current ip address. [CODE=python]if most_recent_ip != current_ip: print "Your IP changed!" else: pass[/CODE] Also, your last 3 lines don't really do much. ;) | |
Re: A good rule of thumb: Get your data (whether it be from a file, user input, etc...) and THEN do stuff to it. It looks like you're trying to open your input file and also write to your output at the same time. So, if booklist.txt looks like this: book1 … | |
Hey all, I'm working on a project combining a javascript bookmarklet and a php script that lets users mail the url of the site they are currently browsing to their email address. I had a PHP issue solved over in the PHP forum: [url]http://www.daniweb.com/forums/thread202375.html[/url] But now I have a new … | |
Re: I would use os.listdir, and shutil.move (or copy). Here's a useful function to sort by extension: [CODE=python]def filterbyext(filelist,ext): """Returns all files of type ext in filelist""" returnfiles = [] for item in filelist: x = item.split(".") try: #Take all files of THIS type if str(x[1]) == ext: returnfiles.append(item) except IndexError: … |
The End.