reading file to list

Rhodri James rhodri at wildebst.demon.co.uk
Mon Jan 19 19:49:13 EST 2009


On Sun, 18 Jan 2009 08:31:15 -0000, Xah Lee <xahlee at gmail.com> wrote:

> On Jan 17, 10:25 am, Tino Wildenhain <t... at wildenhain.de> wrote:
>> > [[int(x) for x in line.split()] for line in open("blob.txt")]
>
> Nice (python code).
>
> Few comments:
>
> • the above code is borderline of atypical. e.g. it is not a average
> python code would produce or one'd seen in corporate python code.

I can't imagine why not.  It's clean and clear, after all.  If I
needed to do the slightly odd processing that it's written to do,
the only change I'd make for production code is to wrap the file
object in a 'with' statement.

> • voodoo like the above makes me dislike python. To me, the one
> advantage of python is its clarity enforced by its syntax.
> Specifically, the forced indendation and quite simple semantics.
> However, the way i've seen Guido's propensities and how python 3 is
> moving to, it is becoming more mumbo jumbo of computer sciency OOP
> jargons with syntax soup. (with iterators, enumerators, list
> comprehension... shits forced upon the users)
>
> The above line illustrate well the ad hoc syntax soup nature python is
> moving into.

To a native English speaker, it illustrates entirely the reverse.
List comprehension is actually quite a linguistically natural way
to express the iterative construction of a list.

-- 
Rhodri James *-* Wildebeeste Herder to the Masses



More information about the Python-list mailing list