This is my first program in Python

godcha at my-deja.com godcha at my-deja.com
Thu Jan 18 04:30:09 EST 2001


In article <3a66a585.268350144 at news.tcn.net>,
  rzilavec at tcn.net wrote:
>
> 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()
>
Your question is not clear...

But I read and tried your code above, it is correct and working
perfectly : it prints the first characters until the first colon (:) of
each line of the /tmp/globs file.

> 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
Godefroid Chapelle
BubbleNet sprl
Louvain-la-Neuve Belgium


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list