Re: New to Python - Easy way to open a text file



On Mar 30, 11:39 am, Marc 'BlackJack' Rintsch <bj_...@xxxxxxx> wrote:
In <1175270675.296617.83...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>, kyosohma wrote:
I'm not familiar with ezt formats, however reading a text file is a
breeze.

This sentence doesn't match the code that follow. It's really simpler
than that ``while`` loop.

f = open(r'pathToFile')
while True:
line = f.readline()
if not line: break
# do something with the line of text such as print it.

f.close()

f = open(r'pathToFile)
for line in f:
# do something with the line of text such as print it.
f.close()

Ciao,
Marc 'BlackJack' Rintsch

Yes, the "while" is lame, I admit it. But sometimes you just gotta go
old school!

Mike

.



Relevant Pages

  • Re: New to Python - Easy way to open a text file
    ... breeze. ... Yes, the "while" is lame, I admit it. ... But sometimes you just gotta go ... old school! ...
    (comp.lang.python)
  • Re: newbie and num-entries
    ... In school we were given ... > recalculating all the time. ... It just gets recalculated each time through a loop. ... There is probably an equal amount of overhead in calling num-entries as ...
    (comp.databases.progress)
  • Re: Small Towns
    ... the loop all night. ... railroad tracks through town, not even the cop. ... gotta love it ...
    (rec.woodworking)
  • Re: Problem getting a form to open to a related record.
    ... It's really a breeze, just one or two "gotta know" things. ... short how-to on another forum and they included it in their tutorials section. ...
    (microsoft.public.access.forms)
  • Re: newbie and num-entries
    ... In school we were given a rule of thumb that if you needed a value more then twice in a method or procedure, calculate it and store it in a temp variable instead of recalculating all the time. ... While reading some of my co-workers code and the documentation it appears that the use of num-entries is exempt from this rule of thumb and no one ever get the number of entries and stores them for use in a loop. ...
    (comp.databases.progress)