Autocoding project proposal.
Alex Martelli
aleax at aleax.it
Mon Jan 28 02:00:24 EST 2002
Kragen Sitaker wrote:
...
>> Surely what would make more sense to a non-programmer is something like
>> (using pseudo-AppleScript):
>>
>> get the count of the lines of file 'foo.txt'
>
> The Python of this is len(open('foo.txt').readlines()) --- not as
I think the average non-programmer might have a fractionally easier
time with len(file('foo.txt').readlines()) -- Python 2.2's "file('foo.txt')"
being an epsilon closer to "the file 'foo.txt'" than the backwards
compatible "open('foo.txt')" which reads more like an imperative of
the verb "to open". If/when Python's len is extended to accept an
iterator argument,
len(file('foo.txt'))
might be easier (or I guess it might confuse some non-programmers,
as "the length of file foo.txt" is not so obviously "the number of lines
of" rather than, say, "the size in bytes of").
Alex
More information about the Python-list
mailing list