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
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
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
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
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
/>/
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
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/?
_
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
"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
"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
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()"
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
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_
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
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
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
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
"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
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
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
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
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,
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
23 matches
Mail list logo