On 2005-02-08, Marc Huffnagle <[EMAIL PROTECTED]> wrote:
>>>for line in file(...):
>>> # do stuff
> When you read a file with that method, is there an implied close() call
> on the file? I assume there is, but how is that handled?
The file will be closed when the the file object is deleted b
Marc
I don't know how it is handled, but I expect also that there is an implied
close().
thanks
Caleb
When you read a file with that method, is there an implied close() call
on the file? I assume there is, but how is that handled?
--
http://mail.python.org/mailman/listinfo/python-list
Marc Huffnagle wrote:
When you read a file with that method, is there an implied close() call
on the file? I assume there is, but how is that handled?
[...]
for line in file(...):
# do stuff
As I understand it, the disk file will be closed when the file object
is garbage collected. In CPytho
When you read a file with that method, is there an implied close() call
on the file? I assume there is, but how is that handled?
Caleb Hattingh wrote:
Peter, that was very clear, thanks.
So not only is
for line in file(...):
# do stuff
the most elegant, it is also the fastest. file.readlines(
Peter, that was very clear, thanks.
> So not only is
>
> for line in file(...):
># do stuff
>
> the most elegant, it is also the fastest. file.readlines() comes
close, but
> is only viable for "small" files.
--
http://mail.python.org/mailman/listinfo/python-list
Caleb Hattingh wrote:
>> Yes, you can even write
>>
>> f = open("data.txt")
>> for line in f:
>> # do stuff with line
>> f.close()
>>
>> This has the additional benefit of not slurping in the entire file at
>> once.
>
> Is there disk access on every iteration? I'm guessing yes? It shouldn'
Caleb Hattingh wrote:
Peter
Yes, you can even write
f = open("data.txt")
for line in f:
# do stuff with line
f.close()
This has the additional benefit of not slurping in the entire file at
once.
Is there disk access on every iteration? I'm guessing yes? It
shouldn't be an issue in the va
Caleb Hattingh wrote:
Peter
Yes, you can even write
f = open("data.txt")
for line in f:
# do stuff with line
f.close()
This has the additional benefit of not slurping in the entire file at
once.
Is there disk access on every iteration? I'm guessing yes? It
shouldn't be an issue in the va
Peter
Yes, you can even write
f = open("data.txt")
for line in f:
# do stuff with line
f.close()
This has the additional benefit of not slurping in the entire file at
once.
Is there disk access on every iteration? I'm guessing yes? It shouldn't
be an issue in the vast majority of cases,
[EMAIL PROTECTED] wrote:
In article <[EMAIL PROTECTED]>, Peter Nuttall wrote:
On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
Hi Alex
Assuming you have a file called "data.txt":
***
f = open('data.txt','r')
lines = f.readlines()
f.close()
for line in lines:
print line
***
Can you
Peter Nuttall wrote:
> On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
>> Hi Alex
>>
>> Assuming you have a file called "data.txt":
>>
>> ***
>> f = open('data.txt','r')
>> lines = f.readlines()
>> f.close()
>> for line in lines:
>> print line
>> ***
>>
>
> Can you not write
In article <[EMAIL PROTECTED]>, Peter Nuttall wrote:
> On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
>> Hi Alex
>>
>> Assuming you have a file called "data.txt":
>>
>> ***
>> f = open('data.txt','r')
>> lines = f.readlines()
>> f.close()
>> for line in lines:
>> print line
>
On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
> Hi Alex
>
> Assuming you have a file called "data.txt":
>
> ***
> f = open('data.txt','r')
> lines = f.readlines()
> f.close()
> for line in lines:
> print line
> ***
>
Can you not write this:
f=open("data.txt", "r")
for line
David Douard wrote:
> Marcel van den Dungen wrote:
>
>> alex wrote:
>>> Hi,
>>>
>>> I am a beginner with python and here is my first question:
>>> How can I read the contents of a file using a loop or something? I open
>>> the file with file=open(filename, 'r') and what to do then? Can I use
>>>
Marcel van den Dungen wrote:
> alex wrote:
>> Hi,
>>
>> I am a beginner with python and here is my first question:
>> How can I read the contents of a file using a loop or something? I open
>> the file with file=open(filename, 'r') and what to do then? Can I use
>> something like
>>
>> for xxx i
alex wrote:
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
Yes, indeed you can. That's by no means *a
alex wrote:
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
Thanks for help
Alex
take a look at this:
Hi Alex
Assuming you have a file called "data.txt":
***
f = open('data.txt','r')
lines = f.readlines()
f.close()
for line in lines:
print line
***
Will print each line of the file.
You can make a huge investment by setting 2 or 3 hours aside to go through
the Python tutorial, which gets insta
Hi,
I am a beginner with python and here is my first question:
How can I read the contents of a file using a loop or something? I open
the file with file=open(filename, 'r') and what to do then? Can I use
something like
for xxx in file:
Thanks for help
Alex
--
http://mail.python.org/m
19 matches
Mail list logo