Perl is worse! (was: Python is Wierd!)
Chris Lawrence
quango at watervalley.net
Fri Jul 28 00:42:17 EDT 2000
On Fri, 28 Jul 2000 03:29:06 GMT, Steve Lamb <grey at despair.rpglink.com> wrote:
> None could be converted into an empty list. None is nothing. I fail to
>see how you can't populate a list with a single nothing.
Reasonable enough. Though you're not populating a list with a single
nothing; you're making an empty list. OTOH, by the logic below, why
not [None] instead of []?
> 1 is a single value. I fail to see why that cannot be converted to [1]
>which is allowed, btw.
>a = [1]
>a
>
> 123 is a single value. I fail to see why that cannot be converted to
>[123] which, again, is allowed. See above.
Not sure about these. If you want a one-element list, say so. x =
[1] is concise. x = list(1) ain't. If [] offends your sensibilities,
try x = list(1,).
> "abc" could either be a single value or a sequence. It is converted as
>["a", "b", "c"]. Of course, the same /could/ be said for the above. However,
>let's play around with this one since it is the only one that works somewhat
>as expected in conversion.
"abc" is a string. Strings are immutable sequences in Python.
list((1,2,3)) = [1,2,3]. Same principle.
>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. I'd think, then,
>that we'd not split the string up in the first place and consider it a single
>value for a single entry in a list. IE, ["abc"]. But, of course, dropping
>back from a list to a str isn't perfect since you're going from a more complex
>structure into a simple data set.
How does Python know you want "['a','b','c']" instead of "['abc']"?
(And wouldn't you *really* expect "abc"?) It can't. But logic
suggests that ['aa', 'b', 'c'] isn't the same thing as ['a', 'a', 'b',
'c'], yet your representation would say they are the same.
This strikes me as type-based magic, which Python tries to avoid.
> How did I run across this? Because I wanted to create an empty name each
>time a class instance is created. Since I was building the class I didn't
>know if I was going to use a list or a str. I figure I could just set it
>to None and then manipulate it later. Nope. Couldn't even convert it even
>though the conversion seems quite straightforward to me. None into any
>structure should yield and empty of that structure. We can have empty
>strings, tuples, lists and directories. Funny thing, though. I can do this
>and it works just fine:
Huh? Python is a strongly typed language. None is an instance (the
sole instance, natch) of a NoneType variable. Should NoneType things
transmute themselves into other types of things at the drop of a hat?
This sounds fishily like Perlish automagic conversion.
> However, if we want to create the namespace with nothing we cannot because
>we cannot convert it for later use. Thus, we are back to declaring variables
>except this time we're doing it with automagical (implicit) means instead of
>explicit.
Sure you can.
x = None
...
for y in range(10):
if x is not None:
x = x + y
else:
x = y
Which begs the question: why would you want to declare a variable
without knowing what you're going to stick in it?
(Incidentally, you're not creating a namespace, you're making an entry
in a particular namespace...)
> 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.
Hmm, works in JPython too. And Python 2.0b1. Maybe it's a feature ;-)
Frankly, I don't know how you'd get None back. And it will play havoc
with things:
None = 1
if None:
print 'Hello'
I suspect Guido will tell you, "don't do that." ;-)
Chris
--
=============================================================================
| Chris Lawrence | Your source for almost nothing of value: |
| <quango at watervalley.net> | http://www.lordsutch.com/ |
| | |
| Debian Developer | This address has been spam-proofed. |
| http://www.debian.org/ | All spam goes to your postmaster. |
=============================================================================
More information about the Python-list
mailing list