This is my first program in Python
Richard Zilavec
rzilavec at tcn.net
Thu Jan 18 03:40:10 EST 2001
I've spent the last few weeks trying to find a good book on Python.
Seems that most stores don't carry a large selection, however I found
The Quick Python Book.. The material seems to flow in the right
direction and the fonts are easy on the eyes.
Anyways, I wrote my first program but was stumped on readline(). I
could get the first line, but not the rest of the file. I tried
searching python.org and could not find an example.... well here it
is:
import string
file = open("/tmp/globs", 'r')
for line in file.readlines():
(first,second) = string.split(line,':',1)
print first
file.close()
This was my first attempt, which looks like it should work but failed:
invalid syntax. Is this not possible?
while line = file.readlines():
Am I using string.split properly?
I was quite happy with how easy this was to put together, I'm just not
sure if its totally correct.
--
Richard Zilavec
rzilavec at tcn.net
More information about the Python-list
mailing list