Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
I'd suggest reading the data from the match_zips into a list, and if the format isn't correct, doing some post-processing on it. But there's no way to advise on that since we weren't given the format of either file. zipdata = match_zips.readlines() Then you can do an if XXX in zipdata

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread Dave Angel
Alan Gauld wrote: "TGW" wrote I go the program functioning with lines = [line for line in infile if line[149:154] not in match_zips] But this matches records that do NOT match zipcodes. How do I get this running so that it matches zips? Take out the word 'not' from the comprehension? T

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
Sorry - my mistake - try: infile = open("filex") match_zips = open("zippys") result = [line for line in infile if line in match_zips] print result When I apply the readlines to the original file, It is taking a lot longer to process and the outfile still remains blank. Any suggestions? #!/usr

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
Sorry - my mistake - try: infile = open("filex") match_zips = open("zippys") result = [line for line in infile if line in match_zips] print result okThanks...This should do it: #!/usr/bin/env python infile = open("filex") zips = open("zippys") match_zips = zips.readlines() results = [lin

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread bob gailer
Please reply-all so a copy goes to the list. On 4/4/2010 10:02 PM, TGW wrote: >/ I wrote a script that compares two text files (one zip code file, and />/ one address file) and tries to output records that match the />/ zipcodes. Here is what I have so far: />/ />/ #!/usr/bin/env python />/

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread bob gailer
On 4/4/2010 5:18 PM, TGW wrote: I wrote a script that compares two text files (one zip code file, and one address file) and tries to output records that match the zipcodes. Here is what I have so far: #!/usr/bin/env python # Find records that match zipcodes in zips.txt def main(): infile

Re: [Tutor] Menu data from file

2010-04-04 Thread Lie Ryan
On 04/05/10 08:54, Alan Gauld wrote: > Thats right you will need to parse the data to convert it into the > format you want. > This is one reason you might find it easier to use XML for storing the data > and use a tool like ElementCTree to parse it. s/ElementCTree/ElementTree/? _

Re: [Tutor] Menu data from file

2010-04-04 Thread Alan Gauld
I can not loop over each list item like: for eachMenuData in self.menuData(): because when I read external txt file: f=open(listFile,'r') lines=f.readlines() f.close() I get the list of file lines instead of list of

Re: [Tutor] Matching zipcode in address file

2010-04-04 Thread Alan Gauld
"TGW" wrote I go the program functioning with lines = [line for line in infile if line[149:154] not in match_zips] But this matches records that do NOT match zipcodes. How do I get this running so that it matches zips? Take out the word 'not' from the comprehension? -- Alan Gauld Author

Re: [Tutor] constructor

2010-04-04 Thread Alan Gauld
"Shurui Liu (Aaron Liu)" wrote Sorry, let me specify. I think comptuter will print out those two sentences like this: A new critter has been born! Hi. I'm an instance of class Critter. A new critter has been born! Hi. I'm an instance of class Critter. class Critter(object): """A virtual p

Re: [Tutor] constructor

2010-04-04 Thread Dave Angel
Shurui Liu (Aaron Liu) wrote: I am studying about how to create a constructor in a Python program, I don't really understand why the program print out "A new critter has been born!" and "Hi. I'm an instance of class Critter." twice. I guess is because "crit1 = Critter() crit2 = Critter()"

[Tutor] Fw: Menu data from file

2010-04-04 Thread ALAN GAULD
forwarding to the list. Please use Reply All when replying to the list otherwise it is only a reply to the original poster. Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ > >- Forwarded Message >From: Neven Goršić >To: Alan Gauld >Sent: Sunday, 4 April

[Tutor] Matching zipcode in address file

2010-04-04 Thread TGW
I wrote a script that compares two text files (one zip code file, and one address file) and tries to output records that match the zipcodes. Here is what I have so far: #!/usr/bin/env python # Find records that match zipcodes in zips.txt def main(): infile = open("/Users/tgw/NM_2010/NM_

Re: [Tutor] constructor

2010-04-04 Thread Emile van Sebille
On 4/4/2010 11:11 AM Shurui Liu (Aaron Liu) said... Sorry, let me specify. I think comptuter will print out those two sentences like this: It's a little more interesting as you move forward from here. This is a small step... class Critter(object): """A virtual pet""" def __init__(s

Re: [Tutor] constructor

2010-04-04 Thread Lie Ryan
On 04/05/10 04:11, Shurui Liu (Aaron Liu) wrote: > But the result I got from computer is like this: > A new critter has been born! > A new critter has been born! > > Hi. I'm an instance of class Critter. > > Hi. I'm an instance of class Critter. Because you tell it to do it in that order: cr

Re: [Tutor] constructor

2010-04-04 Thread Shurui Liu (Aaron Liu)
Sorry, let me specify. I think comptuter will print out those two sentences like this: A new critter has been born! Hi. I'm an instance of class Critter. A new critter has been born! Hi. I'm an instance of class Critter. But the result I got from computer is like this: A new critter has be

[Tutor] constructor

2010-04-04 Thread Shurui Liu (Aaron Liu)
I am studying about how to create a constructor in a Python program, I don't really understand why the program print out "A new critter has been born!" and "Hi. I'm an instance of class Critter." twice. I guess is because "crit1 = Critter() crit2 = Critter()" But I don't understand how did co

Re: [Tutor] Menu data from file

2010-04-04 Thread Alan Gauld
"Neven Gorsic" wrote I would like to import menu data from external txt file, but not as import menudata.py, because then py2exe makes problems ... I would like to preserve list structure like: Yes that's a good idea. (("File", ("&New\tCtrl+N", "Create new blank script", self.onN

Re: [Tutor] Help with simple text book example that doesn't work!!!

2010-04-04 Thread Hugo Arts
On Sun, Apr 4, 2010 at 3:15 PM, Brian Drwecki wrote: > > As for the exact error codehere it is. > > while True: >     reply = raw_input('Enter text:') >     if reply == 'stop': >     break >     elif not reply.isdigit(  ): >     print 'Bad!' * 8 >     else: >     print int(rep

Re: [Tutor] Help with simple text book example that doesn't work!!!

2010-04-04 Thread Brian Drwecki
Python version Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information As for the exact error codehere it is. >>> while True: reply = raw_input('Enter text:') if reply == 'stop': b

[Tutor] Menu data from file

2010-04-04 Thread Neven Goršić
Hi! I would like to import menu data from external txt file, but not as import menudata.py, because then py2exe makes problems ... I would like to preserve list structure like: (("File", ("&New\tCtrl+N", "Create new blank script", self.onNew), ("&Open\tCtrl+O", "Opens call scrip

Re: [Tutor] Help with simple text book example that doesn't work!!!

2010-04-04 Thread wesley chun
similarly, you get an error if: "print int(reply) ** 2 print 'Bye'" ... is all a single line and/or if you mixed spaces and TABs. -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 "Python Fundamentals", Prentice Hall,

Re: [Tutor] Help with simple text book example that doesn't work!!!

2010-04-04 Thread Steven D'Aprano
On Sun, 4 Apr 2010 03:40:57 pm Brian Drwecki wrote: > Hi all... I am working from the Learning Python 3rd edition published > by O'Reily... FYI I am trying to learn Python on my own (not for > course credit or anything).. I am a psychologist with very limited > programming experience.. I am anal, a