304 Posted Topics
Re: From your code it appears, that you want to allow the following formats: yyyy,mm,dd yy,mm,dd -> 20yy,mm,dd yyyy,m,d-> yyyy,0m,0d You either allow only strict format or face the consequences... [code] import datetime def event(): ''' ask user a date and returns it in a yyyy/mm/dd format User input format: year,month,day … | |
Re: Can you isolate the problem in a code that can be run on its own? I think using global statement in python is unfortunate. 99% of the cases, it is bad design. Most basic books on programming suggest the same and not only in python. [URL="http://stackoverflow.com/questions/146557/do-you-use-the-global-statement-in-python"]See stackoverflow[/URL] Try setting up … | |
Re: Maybe look at [url]http://code.activestate.com/recipes/496737/[/url] I think the C implementation of addition is other in python than in C. | |
Re: If your php file is pure html and javascript, then theoretically you can include it into the template you are using in python. How you do that, depends on the templating system, you are using. Since you are not asking of a specific templating system (mako, genshi, cheetah..), you are … | |
Re: Have you read this: [url]http://www.oreillynet.com/onlamp/blog/2007/08/pymotw_subprocess_1.html[/url] ? | |
Re: Your comment sais: # TODO: compute the percentage of filler words to total words # lower percentage is more compact # students to fill this in; not provided So you get out the punctuation from the text, you make the tokens (words) and store it in the variable "tokens". You … | |
Re: Try: time.sleep [url]http://www.daniweb.com/forums/thread63297.html#[/url] | |
Re: I think you should post your question to the psp support forum. If any. | |
Re: All I can propose, that you use a database. The ordered dictionary is only usable, if you know the queries beforehand or you have hardly any data. I have made, a diagram about, how I understand your data structure, but Dia crashed and I have lost it. If you are … | |
Re: [URL="http://coding.derkeiler.com/Archive/Python/comp.lang.python/2003-12/3091.html"]http://coding.derkeiler.com/Archive/Python/comp.lang.python/2003-12/3091.html[/URL] | |
Re: Do not use "is", unless you really mean object identity, which you obviously don't. Use: system == 'Conferences' community == 'Arts' I do not know what in communities is. If it is a list, then a copy of a list will never be equal or identical with a string literal. … | |
Re: Most pygame tutorial give you an implementation of simple bouncing. An ideal round ball hits on an ideal straight wall without spinning and losing energy. For example: [url]http://www.pygame.org/docs/tut/intro/intro.html[/url] [url]http://www.penzilla.net/tutorials/python/pygame/[/url] I am not sure I know what an air hockey game is. The only difference I can think of, can be … | |
Re: I recommend reading the documentation. Anyway: str.replace("\\",'/') | |
Re: Something like this? [CODE=python] gpsstring='''the string you have just mentioned''' gpgaline=None gprmcline=None for line in gpsstring: if line.startswith('$GPGGA,'): gpgaline=line [/CODE] | |
Re: [CODE]print "%-14s|%-10s|%-5s" % header[:3][/CODE] BTW Your comment is not accurate. The header is already read in that line. | |
Re: Instead of: subject = subjects[0][1] Try: subject.append(subjects[0][1]) | |
Re: Hello Dmc! First, there are bugs and small mistakes in your code. mazefile.close is not a function call, so it does not close the file. It makes no problem because the file is automatically closed at python exit. Correctly: mazefile.close() You do not initialize the x variable in start function. … | |
Re: Hello Democles! Where is your sword? ;) Or was that Damocles? I think it is a difficult question, how someone learns a programming language. I (and the Somerville book) would say, there are two main phases of the process. First you have to build the necessary mindset. This includes understanding … | |
Re: What is the expected output for sings? The empty string? If you remove s,ing and s from the word in that order, the empty string remains... If that is so.... I would make a stem_word function, that would look like: [CODE] def stem_word(word): word_new=None for e in endings: if word.endswith(e): … ![]() | |
Re: I would look up the wget manual. If that does not help, you can peek into the file, extract the date from it, and put the file wherever you want. [CODE] import os from os.path import join import re s=re.compile('.*?<meta name=\"OriginalPublicationDate\" content=\"(.*?)" />.*?',re.M|re.S) _dir="news.bbc.co.uk/2/hi/business/" for f in os.listdir(_dir): #print open(_dir+"/"+f).read() … | |
Re: You can use the observer pattern. [CODE] class Observed(object): def register_observer(self,observer): self.observer=observer def notify(self): self.observer.update(self) class Observer(object): def update(self,other): print(self,"gets that ",other," has moved") #decide what to do pass class Something(Observer,Observed): def __init__(self,x,y): self.x=x self.y=y #super(Something,self).__init__() def move_to(self,x,y): self.x=x self.y=y self.notify() def update(self,other): super(Something,self).update(other) if other.x<self.x: self.move_to(self.x-1,self.y)# or whatever o1=Something(1,2) … | |
Re: Could not reproduce it on python 2.6.2 linux either. Maybe you have run the pyc version, which was older. | |
Re: Your description is incorrect. This function will never return 'radar' on any string input, because it needs another parameter. Your loop does not exit. You increment num, but the loop's exit expression does not depend on it. It possibly exits on index error if num becomes too large. At first … | |
A brute force method. Finds the FIRST and SHORTEST periodicity in the input list. | |
Re: Please use [URL="http://www.daniweb.com/forums/announcement114-3.html"]code tags[/URL], even if it is quick. What exactly is your question? | |
Re: We do not make private attributes in python, except in very rare cases. You can shadow the attribute access with "property" decorator later. The Item and the Project class is trying to reimplement the [URL="http://docs.python.org/dev/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields"]named tuple[/URL], which is present in python 2.6 or later. From a design point of view … | |
Re: First of all, please read [URL="http://www.daniweb.com/forums/announcement114-3.html"]this[/URL]. It is on the very beginning of the forum. Your indent cannot be reconstructed from your post, so your code can only be guessed. I think your problem is not, that you are new to python. In any language there would be a problem … | |
Re: I would try this one: [url]http://docs.python.org/library/signal.html[/url] | |
Re: This is not a python issue. However... This oracle error comes out, when in some expression an implicit or explicit conversion fails on some line and field value. Most likely your [code]:DATAI[/code] and [code]:DATAF[/code] bind variables are not in the format 'yyyy-mm-dd hh24:mi:ss' | |
Re: [URL="http://www.daniweb.com/forums/announcement114-3.html"]Please[/URL] use code tag. I see two problems with your code: 1. No data will be written to the text list. Its a logical thing, you know.:) If you exit the loop when a line starts with "<" or ends with ":>", and you do not process a line otherwise, … | |
Re: Let me give you an example. There are two files. The first is compute.py and has the code: [code=python] def sumup(a,b): return a+b [/code] And there is your program, main.py [code=python] import compute print compute.sumup(2,3) [/code] The question is, how will python know where to find this compute module? The … | |
Re: A classic error in python3. You are concatenating a byte array (rawdata) to a string(data). Try converting the data to bytes with encoding or do not convert it to string. Try googling the error code to get the notion. | |
Re: Have you checked the firewall? Try open the server port higher (>5000). Check out if [URL="http://www.prasannatech.net/2008/07/socket-programming-tutorial.html"]minimal[/URL] implementations are working. | |
Re: I would read in the first csv into a dictionary with title- url key-value pairs. Then go through the second large one line by line, and append the looked up values, and write it to a new file. The code goes something like this (not tested): [code=python] import csv urlReader … | |
Re: You unnecessary use the list. [code=python] def columns(infile, outfile): f = open(infile,'r') o = open(outfile,'w') col = raw_input('Please select a column from your input file, %s:' % (infile)) col = int(col) - 1 for line in f: line = line.strip() if line: # Split each line into columns line = … | |
Re: I am running file processing with larger (>1G) files on a fare more weaker machine. I hardly believe your case ran into a limitation. In my experience the never ending program is more possible, than the one running out of memory. Try catching the exception that occurs, and print out … | |
Re: Pyexcelerator is is abandoned and forked. Use xlrd and xlwt. | |
Re: A pragmatic one time solution: The test.txt contains the above string. [code=python] st=open("test.txt").read() delimiter="><" tokens=st.split(delimiter) fo=open("test_out.txt","w") count=1 for line in tokens: if line.startswith("ARG") and line.endswith("ARG"): firstarg=line.find("ARG")+3 line=line[:firstarg]+str(count)+line[firstarg:]+str(count) count+=1 fo.write(line) fo.write(delimiter)#FIXME last delimiter is too much fo.close() [/code] | |
Re: I think this is, what you need: [url]http://www.pygame.org/docs/ref/key.html#pygame.key.get_pressed[/url] Look at the comments, too. | |
Re: You should check the type first, and if it is a keyboard event, than get the key pressed. [code=python] while True: clock.tick(60) p.update() for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: pygame.quit() return elif event.key == pygame.K_LEFT: p.walk_left() elif event.key == pygame.K_RIGHT: p.walk_right() elif event.key == … | |
Re: The question is far too general. You need to be more specific. You can (in decreasing difficulty): [LIST] [*]mount other systems directory - via smb, nfs etc - and import from there [*]download - via smb, ftp, http etc - other systems directory and import it locally [*]Use import hooks … | |
Re: In [URL="http://www.daniweb.com/forums/thread193501.html"]your other thread[/URL] the image shows up. I've checked. | |
Re: Well, if you want the hard part... Coming from a financial background I can assure you, that saving entries into a csv file permanently is a a bad idea. Unless the only purpose for this file is to import it to something more robust. Deleting transactions looks like a bad … | |
Re: You can use the magic of ascii:) ord("a")==97 chr(97)=="a" | |
| |
Re: Good luck with it. May I [URL="http://www.daniweb.com/forums/post870435-10.html"]recommend[/URL] my thoughts on another guessing game? | |
Re: Well, I would say it is because you do not wait for user input. Anyway, this game not so complicated to implement. No need to separate files and so on... To prove my opinion I made one, in 10 minutes. Most of the time went debugging the match_guess method. It … | |
Re: [URL="http://docs.python.org/library/site.html"]http://docs.python.org/library/site.html[/URL] | |
Re: First of all, I don't know what the code does. From a merely technical point of view, I say the followings. I think you should improve the code before improving the speed. The majority of the code seems to be copy-pasted. All the "cases" can possibly merged into one codeblock … | |
Re: I do not know the TK library ( It is disturbing to me, that the application is a frame object, too), but syntactically: [code] class Application(Frame): def __init__(self, master,player1, player2): [/code] should do the trick. |
The End.