RE: print is not a function

Discussion in 'Python' started by Marc Boeren, Oct 8, 2003.

  1. Marc Boeren

    Marc Boeren Guest

    Hi,

    > quite often there is a need to just print out the items of a list.
    > [ prt(x) for x in my_list ]


    for x in my_list: print x

    (no need for a list comprehension here)


    Cheerio, Marc.
    Marc Boeren, Oct 8, 2003
    #1
    1. Advertising

  2. Marc Boeren

    Karl Scalet Guest

    Marc Boeren wrote:

    > Hi,
    >
    >
    >>quite often there is a need to just print out the items of a list.
    >>[ prt(x) for x in my_list ]

    >
    >
    > for x in my_list: print x
    >
    > (no need for a list comprehension here)
    >
    >
    > Cheerio, Marc.
    >


    yes, thanks, I know list comprehension is not absolutely needed.
    But
    [ prt(x) for x in my_list if x%2 ]
    would become
    for x in my_list: if x%2: print x
    and so on.
    I think you always can substitute listcomrehension with
    a for loop. That's what we had to do in early versions
    anyhow. But if one prefers list comprehension over a for
    loop because of readability (well, that's a matter of
    taste) a prt() function or equivalent would be nice :)

    Karl
    Karl Scalet, Oct 8, 2003
    #2
    1. Advertising

  3. Karl Scalet wrote:
    ...
    > anyhow. But if one prefers list comprehension over a for
    > loop because of readability (well, that's a matter of
    > taste) a prt() function or equivalent would be nice :)


    ....and you'd end up with a list of n copies of None as
    a result to throw away... weird...!

    Anyway, the 'equivalent' is sys.stdout.write('%s\n'%x).


    Alex
    Alex Martelli, Oct 8, 2003
    #3
  4. Karl Scalet <> wrote in message news:<bm0p34$hchtl$-berlin.de>...
    > But if one prefers list comprehension over a for
    > loop because of readability (well, that's a matter of
    > taste) a prt() function or equivalent would be nice :)


    Which is reason enough for not adding it. Why make it easier for
    people to write ugly and inefficient code?

    Jeremy
    Jeremy Fincher, Oct 8, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q1NoYXJwZ3V5?=

    print gridview but not print template fields

    =?Utf-8?B?Q1NoYXJwZ3V5?=, Sep 11, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    5,996
    =?Utf-8?B?Q1NoYXJwZ3V5?=
    Sep 11, 2006
  2. keto
    Replies:
    0
    Views:
    897
  3. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    335
    David Cournapeau
    Dec 30, 2008
  4. Matt
    Replies:
    1
    Views:
    268
    Randy Webb
    Nov 20, 2004
  5. FAQ server
    Replies:
    1
    Views:
    102
Loading...

Share This Page