Re: [perl-python] 20050121 file reading & writing

2005-01-23 Thread Erik Max Francis
Bob Smith wrote: To do this efficiently on a large file (dozens or hundreds of megs), you should use the 'sizehint' parameter so as not to use too much memory: sizehint = 0 mylist = f.readlines(sizehint) It doesn't make any difference. .readlines reads the entire file into memory at once. -- E

Re: [perl-python] 20050121 file reading & writing

2005-01-23 Thread Bob Smith
Erik Max Francis wrote: Bob Smith wrote: To do this efficiently on a large file (dozens or hundreds of megs), you should use the 'sizehint' parameter so as not to use too much memory: sizehint = 0 mylist = f.readlines(sizehint) It doesn't make any difference. .readlines reads the entire file in

Re: [perl-python] 20050121 file reading & writing

2005-01-23 Thread Fredrik Lundh
Erik Max Francis wrote: >> To do this efficiently on a large file (dozens or hundreds of megs), you >> should use the >> 'sizehint' parameter so as not to use too much memory: >> >> sizehint = 0 >> mylist = f.readlines(sizehint) > > It doesn't make any difference. .readlines reads the entire fi

Re: [perl-python] 20050121 file reading & writing

2005-01-22 Thread Bob Smith
Xah Lee wrote: # reading entire file as a list, of lines # mylist = f.readlines() To do this efficiently on a large file (dozens or hundreds of megs), you should use the 'sizehint' parameter so as not to use too much memory: sizehint = 0 mylist = f.readlines(sizehint) -- http://mail.python.org

Re: [perl-python] 20050121 file reading & writing

2005-01-22 Thread Gian Mario Tagliaretti
Xah Lee wrote: > # the second argument of open can be > # 'w' for write (overwrite exsiting file) > # 'a' for append (ditto) > # 'r' or read only are you sure you didn't forget something? > # reading the one line > # line = f.realine() wrong > [...] Maybe you didn't get the fact the you won't

[perl-python] 20050121 file reading & writing

2005-01-22 Thread Xah Lee
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be # 'w' for write (overwrite exsiting file) # 'a' for append (ditto) # 'r' or read only # to actually print to file