enigma wrote:
Do you really need to use the iter function here? As far as I can
tell, a file object is already an iterator. The file object
documentation says that, "[a] file object is its own iterator, for
example iter(f) returns f (unless f is closed)." It doesn't look like
it makes a differen
Do you really need to use the iter function here? As far as I can
tell, a file object is already an iterator. The file object
documentation says that, "[a] file object is its own iterator, for
example iter(f) returns f (unless f is closed)." It doesn't look like
it makes a difference one way or
Stephen Thorne wrote:
On Thu, 27 Jan 2005 00:02:45 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
By using the iterator instead of readlines, I read only one line from
the file into memory at once, instead of all of them. This may or may
not matter depending on the size of your files, but using
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
...
Beware of mixing iterator methods and readline:
[snip]
I hope this concisely indicates that the problem (in today's current
implementations) is only with switching FROM iteration TO other
approaches to reading, and (if the file
Steven Bethard <[EMAIL PROTECTED]> wrote:
...
> Beware of mixing iterator methods and readline:
_mixing_, yes. But -- starting the iteration after some other kind of
reading (readline, or read(N), etc) -- is OK...
> http://docs.python.org/lib/bltin-file-objects.html
>
> next( )
>
Stephen Thorne wrote:
I did all I did in the name of clarity, considering the OP was on his
first day with python. How I would actually write it would be:
inputfile = file('input','r')
inputfile.readline()
data = [map(float, line.split()) for line in inputfile]
Notice how you don't have to call ite
On Thu, 27 Jan 2005 00:02:45 -0700, Steven Bethard
<[EMAIL PROTECTED]> wrote:
> Stephen Thorne wrote:
> > f = file('input', 'r')
> > labels = f.readline() # consume the first line of the file.
> >
> > Easy Option:
> > for line in f.readlines():
> > x, y = line.split()
> > x = float(x)
> > y =
mcg wrote:
> Investigating python day 1:
>
> Data in file:
> x y
> 1 2
> 3 4
> 5 6
>
>
> Want to read file into an array of pairs.
>
> in c: scanf("%d %d",&x,&y)---store x y in array, loop.
>
> How do I do this in python??
> In the actual application, the pairs are floating pt i.e. -1.
Stephen Thorne wrote:
f = file('input', 'r')
labels = f.readline() # consume the first line of the file.
Easy Option:
for line in f.readlines():
x, y = line.split()
x = float(x)
y = float(y)
Or, more concisely:
for line in f.readlines():
x, y = map(float, line.split())
Somewhat more memory
On 26 Jan 2005 20:53:02 -0800, mcg <[EMAIL PROTECTED]> wrote:
> Investigating python day 1:
>
> Data in file:
> x y
> 1 2
> 3 4
> 5 6
>
> Want to read file into an array of pairs.
>
> in c: scanf("%d %d",&x,&y)---store x y in array, loop.
>
> How do I do this in python??
> In the actual
Investigating python day 1:
Data in file:
x y
1 2
3 4
5 6
Want to read file into an array of pairs.
in c: scanf("%d %d",&x,&y)---store x y in array, loop.
How do I do this in python??
In the actual application, the pairs are floating pt i.e. -1.003
--
http://mail.python.org/mailman/l
11 matches
Mail list logo