Perl is worse!

Martijn Faassen m.faassen at vet.uu.nl
Fri Jul 28 16:32:45 EDT 2000


Steve Lamb <grey at despair.rpglink.com> wrote:
[snip]
>     Just playing around try this some time:

> a = None
> list(a)
> a = 1 
> list(a)
> a = 123
> list(a)
> a = "abc"
> list(a)

>     To me all of those could be converted into lists yet only the last one is.

The last one is a sequence, the rest of them aren't sequences so Python
gives up in the face of ambiguity. What result should list(None) give?
What about list(123)?

If you want to put something in a list, that can be done unambigiously:

[None] or [123]

[snip what you expected]

You are expecting different things than I am. That's the problem; Python
just gives up when it sees things like that.

> as expected in conversion.

> a = "abc"
> a
> a = list(a)
> a = str(a)
> a

>     a is now "['a', 'b', 'c']".  Which means we split a string up when
> converting to list but don't concatinate on the way back.

There's string.join() for that:

string.join(a)

Again, str() tries to give you a readable version of whatever you put into
it. Its goal isn't to concatenate anything.

[snip lots of assumptions that just don't work in Python. Your assumptions
are not the same I make, or Python makes]

> a = None
> a = ""

>     Amazing, that.  Automagical conversion from None to an emptry string on
> the assignment operator.  Actually, we both know, and correct me as I may be
> wrong, that it is really reassigning the data space a is pointing to.

Yes, in Python, assignment is *always* a rebinding of the reference. There's
never anything being copied.

>     However, if we want to create the namespace with nothing we cannot because
> we cannot convert it for later use.

That's because you want to convert everything to everything else. In
Python, you don't have this kind of anything to anything else conversion.
If you want to get rid of None, then assign something else to your variable.
You can't do anything with None (except display it and check for it), as 
there's no commonly accepted thing to do with None. Just like there's no
real sense in adding "foo" to 155.

[snips]
>     Like I said, every language has its quirks.  Every language.

Yes, though you're really finding some quirks where they're none; you
just coming with the wrong set of assumptions (Perl's). A few years ago
I tried to learn Perl but happily gave up as soon as I found Python --
Python's assumptions just make more sense than Perl's to me. 

[snip]
>     And just for fun, here's a good quirk for you.  

> None = 1
> a = None
>>>> if a:
> ...   print "foo\n"
> ... 
> foo

>>>> a
> 1

>     I think that is kinda neat, don't you?  

Yeah, that's a pretty awful quirk, I discovered that one a few months ago
and was aghast. Luckily this type of thing rarely happens in Python
(only when you explictly say None = <something>, which is easy enough
to avoid). But it should be forbidden, I think. Trouble is that this would
introduce a special case in the clean name rebinding that is assignment
in Python currently. There's no way to say 'don't rebind this name' in Python,
I think.

[snip]
>     I just don't understand how people can advocate for types and the
> restrictions they impose while, on the other hand, embracing a language that
> is free enough to shoot yourself in the foot by reassigning None.

The difference is of course that reassigning None is extraordinarily rare,
as it can *only* happen when you really write an assignment with None
(not a variable referencing None, no, just 'None') on the left hand
side. Python is by the way *not* a language with 'types and restrictions'
according to most people that come to Python. :)

>     Shoot yourself with "conversion" or with assignments like this, either way
> your foot is shot.  I say learn proper gun safty and aim it elsewhere.  ;)
> Seriously, that isn't to say that None should be restricted from being
> changed, just, uh, anyone know how to change it back aside from restarting
> python?  :)

Cute question. Hm.. 

Yes:

None = __builtins__.None

Now for the real problem:

__builtins__.None = 1

Uh oh.

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list