304 Posted Topics
Re: What is the purpose of this? Anyway, you can parse the input string in TASK.__init__ method. If you want variable arguments, then you should take a look at the `*args, **kwargs` function definitions. [See](http://stackoverflow.com/questions/287085/what-do-args-and-kwargs-mean) | |
Re: For clarification: Global variable is defined by giving it a value at zero indentation level in the .py file. For example in the following code globalvar is printed. globvar=None def some_function(): print globalvar There is a distinction if you want to change the value of the variable or just read … | |
Re: The question is not answered, because you provided too little information. Too many answers are possible. Is this a terminal program, or a gui, or a web application? How do you want to authorize and authenticate the username/password pair. LDAP, PAM, apache, roll your own? | |
Re: The theacher is right. Keep him/her happy :) If interested, I can elaborate on this further. The main function should look like: def main(): hours,rate=get_user_input() regularhours,overtimehours=calculate_hours(hours) regularpay,overtimepay,totalpay=calculate_pay(regularhour,overtimehours,rate) #printing results The calculate_hours functions is like: def calculate_hours(hours): if hours<=40: return hours,0 else: return 40,hours-40 | |
Re: 1. You get zerodivision error if num_files == 0. It is impossible to find any word in nonexistent files, so the probability should be zero. So you should write (and see next point) `probability=count/num_files if numfiles else 0` 2. // is integer division in python. you should: python3: probability=count/num_files python2 … | |
Re: for counter,row in enumerate(reader): if counter<3: continue if counter>5:break writer.writerow(row) # I only want rows 3-5 | |
Re: After the subprocess exits, the environment is "gone". So theoretically you have the following options: * Combine the two commands into one process, so they share the same environment. * Wrap the first command with into a program that returns the environment and run the second command in this one. … | |
Re: This has nothing to do with python. You have to look up the manual of system3, or call for system admin help. Look at the greeting text, what system is it running, and try to google it. | |
Re: It is very unlikely, that open and write does not work properly. More likely is that your program misses the line with the write method call, or you open the file twice without flushing the first time. Consider this example: >>> fp=open("a.txt","a") >>> fp.write("asdf") >>> fc=open("a.txt","a") >>> fc.close() >>> fp.close() | |
Re: There are several lines where the code prints ok. Line count? " Please make a valid choice. <y/n>" is scattered all over the place. How do you know which one is called?! Run the code with idle debug mode to see what is happening. The stack is too deep. You … | |
Re: We generate 0-1000 (random) pieces of a random number between 0 and 500. We count these random numbers in the "stats" dictionary. If a random number a is occuring n times then stats[a]==n. We print out the random numbers that are counted more then 1 time in the stats dict. | |
Re: Please stick to english. I understand german, but this is an english forum... In which line do you get the error? What is this dev object? What is the f object? | |
Re: http://www.openshot.org/screenshots/ Seems to be in gtk. Maybe: http://sayavideoeditor.sourceforge.net/screenshots.shtml google for: python audio/video editor | |
Re: Your "current time" might be misunderstood. The gmtime function returns the local representation of UTC in seconds. If your "current time" is local time, and are in a timezone UTC+1 geographicaly or in time, then the output is correct. Where are you, and when did you run this? If you … | |
Re: Your delegation is not working because `Foo().__len__` is called with Foo() as self and not with Foo()._data as self. There are many ways to mix two classes. Let say you have two classes. One is a dictionary like object, another with some bussiness functionality. You want the two classes in … | |
Re: 1. first solution: c.append(a[count]*(1/(b[count] if b[count]!=0 else 0)) 2. b==0 is invalid. I do not know why. It is surely not what you want. Please post the code, and the error message. 3.More pythonic would be: for count in range(len(a)): try: toappend=a[count]//b[count] #integer division except ZeroDivisionError: toappend=0 c.append(toappend) | |
Re: Mutable objects cannot have the same identity. If you know what mutable means, you can understand that, it leads to a contradiction. Immutable objects **can** have the same id. For immutable objects it is an implementation issue. With other python implementations (stackless, jython) you might get different results. Object identity … | |
Re: Hey Kaushik! What the heck are you talking about? | |
Re: Download the site index page. Search for the html tag that provides automatic rss detection. Return that link. Is that an answer to your question? | |
Re: This gives a small (10%) performance improvement. Tested on a 30 meg file with bytes=bytearray on python 2.7. def blockchecksums2(instream, blocksize=4096): from hashlib import md5 weakhashes = [] stronghashes = [] for chunk in iter(lambda: instream.read(blocksize),""): l = len(chunk) a=0 c=0 for n, i in enumerate(bytes(chunk)): a += i c … | |
| |
Re: You should read about what a function, a funciton call, a return value and a variable are. var = raw_input("Enter temperature: ") temperature = int(var) if temperature < 21: print "temperature to cold" elif temperature > 24: print "temperature to hot" #raw_input() | |
Re: You have very hard times ahead. The main problem is not to decide if it is sqlite3 or any other desktop database. **The main problem is how to synchronise the user's and the main database.** Is there only one user? Or there are many, and can change the same data … | |
Re: I think using min() is cheating. I think, you cannot sort a list without using the length of the list. Take a look at the [sorting algorythms](http://en.wikipedia.org/wiki/Sorting_algorithm) For first I recommend bubble sort. A = [10, 5, 2, 7, 20] for _ in range(len(A)*len(A)): # worst case swapped=False for i … | |
Re: You should install libpython3.3-dev http://packages.ubuntu.com/quantal/i386/libpython3.3-dev/filelist | |
Re: 1. Turtle graphic is not for plotting. [see](http://www.daniweb.com/software-development/python/code/216557/turtle-graphics-python). If it is your homework, than forget it. 2. What is the reason you return the function object instead of the list? 3. I cannot run your code, because you did not provide a testcase. It is hard to help in that … | |
Re: Look at the examples: http://code.google.com/p/pymox/wiki/MoxDocumentation#Basic_Example It is confusing to put not running code in the first chapter, I think it too. | |
Re: from string import maketrans encode=lambda x: x.translate(maketrans(key,alpha)) decode=lambda x: x.translate(maketrans(alpha,key)) It only translates the characters you give in. So lowercase chars are not encoded and decoded. If you on python3 than it wont work. | |
Re: [Docs maybe?](http://docs.python.org/2/library/subprocess.html#subprocess.check_output) Or I did not understand the question. | |
Re: Well it depends obviously. I think first you have to be clear about 1. how is decided which calculation to use 2. Should it be easy to implement new calculation types, modify olders 3. How many of the parameters are and will be shared between the current and the future … | |
Re: Your countryurl variable does not contain a country, but a region. That is what misleads you. You produce excelent quality code, btw. response = urllib2.urlopen('http://www.indexmundi.com/factbook/regions').read() soup = BeautifulSoup(response) row = soup.findAll('li') for link in row: href = link.find('a')['href'] url = "http://www.indexmundi.com" countryurl = url + href #----- regionname=link.find('a').text #----- response … | |
Re: Design your data structures, then the process. We have two files: * available.csv * customer.csv available.csv at first is: seatrow, seatcolumn customer.csv at first is: customerid, seatrow, seatcolumn So the process at first is: open available.csv for reading ask user the customerid check choosen customerid (no spaces, no commas) print … | |
Re: Check your /usr/lib/pythonX/site-packages/pygame/ directory(ies). The imageext.so library cannot be loaded most probably. Usefull can be: http://ubuntuforums.org/showthread.php?t=1508100 http://stackoverflow.com/questions/6539472/installing-pygame-for-python-3-1-2-in-ubuntu | |
Re: The first one is not properly indented, does not run. The question was: How we get the answers. Solution 1: You run the code, look at the output. Solution 2: You run the code with paper and pencil, and look at the result. The second one: We take the numbers … | |
Re: Too much code. How about that? def check(): rows=[[(i,j) for i in range(3)] for j in range(3)] cols=[[(j,i) for i in range(3)] for j in range(3)] diags=[[(i,i) for i in range(3)],[(i,2-i) for i in range(3)]] ss=0 for r in rows+cols+diags: sx=0 so=0 for c in r: v=Grid[c[0]][c[1]] if v=='X': sx+=1 … | |
Re: import random questions=open('file_containing_the_questions_separated_by_newline.txt').readlines() print random.sample(questions,10) > I want to make a trivia game in python. Let's say I have a set of 25 questions, how do I choose 10 random questions from that set without repeats? | |
Re: You get the error, because in line 21 you exit the loop, and not the whole with clause. Either you make a sys.exit at this line, or make a check before line 26: if numrows>0. | |
Re: Wow. That's kind of overkill for this simple task. A oneliner: >>> [s for s in sequence1 if s.lower() not in set(s2.lower() for s2 in sequence2)] You set n = len(sequence2) then you make a loop with n in range(len(sequence2)), which will never be true. | |
Re: You have to solve the equation first. after some equivalent transformations: y*d=a*b-e-x*c If d==0 and c==0 then x,y can be anything if a*b-e==0 else nothing if d==0 and c!=0 then y= anything, x=(a*b-e)/c if d!=0 and c==0 then y=(a*b-e)/d, x is anything if d!=0 and c!=0 then x,y can be … | |
Re: [code] steps=0 while distance: steplen=random.randint(minStep,maxStep) steps+=steplen distance-=steplen return steps [/code] | |
Re: You misspelled it. import MySQLdb The directory's name containing a file named __init__.py can be imported. | |
Re: Like [URL="https://sites.google.com/site/matassaps/home"]this[/URL]? | |
Re: Maybe you are not answered, because nobody understands what you are trying to accomplish. If you want to program a custom client that gets data from a http server, then you can go with urllib, urllib2 or any other application (ie web crawler) that is built on those. [url]http://www.voidspace.org.uk/python/articles/urllib2.shtml[/url] But … | |
Re: [URL="http://py-googlemaps.sourceforge.net/"]Try the python api.[/URL] | |
Re: [code] cl.send("150-Here comes the directory listing\r\n") # received from LIST [/code] Base on: [url]http://tools.ietf.org/html/rfc959[/url] page 35 | |
Re: The GUI part is well defined and easy. But how do you convert these filetypes to pdf? Or is this the hard part? I recommend to split the task into two: Write a command line utility wchich converts a given DWN or DGN file to pdf. Write a gui, with … | |
Re: Source code of [URL="http://pyserial.sourceforge.net/pyparallel.html"]pyparalell[/URL] ? | |
Re: I do not get it this, what is not possible? [code] f = open('/tmp/workfile', 'w') f.write('0123456789abcdef') f.close() f = open('/tmp/workfile', 'rb+') f.seek(5) f.write("I") f.close() [/code] And now I have overwritten the 5th position in the file with "I". In place. | |
Re: I do not have python here at hand but: You open a file, and open again without closing it first. You use a global "file" in a local namespace. Plz do not do that... There is an endless loop. What is i+1 supposed to meand? i=i+1? Import OS will raise … | |
Re: [code] import sys from collections import defaultdict clusterlines = open(sys.argv[1],'r').readlines() my_dict = {} reverse_dict = defaultdict(list) for line in clusterlines: cluster = map(str.strip,line.split()) my_dict[cluster[0]] = tuple(cluster[1:]) for cl in cluster[1:]: reverse_dict[cl].append(cluster[0]) print reverse_dict [/code] I have tested it on the input, you provided. I removed the empty lines. |
The End.