Perl is worse! (was: Python is Wierd!)

Alex Martelli alex at magenta.com
Fri Jul 28 09:16:29 EDT 2000


"Steve Lamb" <grey at despair.rpglink.com> wrote in message
news:slrn8o25nr.e7.grey at teleute.rpglink.com...
    [snip]
>     Define a variable to get the name space in there but you don't know
how it
> is going to be used later on.  a = None.  Now make it a list in a concise
> manner.
>
> for x in range(10):
>   a.append(x)
>
>     Whoops, can't do it.  It isn't a list.  So make it a list.

Right, make it a list.  I.e., instead of
    a=None
start out with
    a=[]
and you're done.  What's hard about this?

> list(a)
> for x in range(10):
>   a.append(x)
>
>     Whoops, can't do it.  None can't be transformed into a list.

Whatever a refers to, the expression statement
    list(a)
is not going to make a refer to anything different than before.

> for x in range(10):
>   if a:
>     a.append(x)
>   else
>     a = [x]
>
>    All that because of type checking?  Jumping through 3 hoops just to get
> done what should be a trivial matter.

Clumsy!  Just set a=[] once, outside of the loop -- how much easier can it
get?


Alex






More information about the Python-list mailing list