Any other Python flaws?
Carsten Geckeler
uioziaremwpl at spammotel.com
Wed Jun 20 20:00:52 EDT 2001
On 20 Jun 2001, Martijn Faassen wrote:
> Carsten Geckeler <geckeler at gmx.net> wrote:
> > On 18 Jun 2001, Martijn Faassen wrote:
[snip]
> >> But since single element tuples are a wart by themselves, this extra
> >> magic is necessary. Perhaps a language is possible where single
> >> element tuples actually are single elements, though that may introduce
> >> other warts.
>
> > So that's your point.
>
> Not the only point. I still think I have a point that the mandatory
> () around a tuple in that place are a wart. I'd have liked it to
> be different but that would mean a change in Python's precendence rules
> that would probably cause other annoyances.
OK, let's assume we make "," higher precedence as "%". Then you can write
the following lines of code:
print "%x" % 1 # gives "0x1"
print "%x %x" % 1, 2 # gives "0x1 0x2"
But when you want to add other elements to the list, you have to do the
following
print ("%x" % 1), 2 # gives "0x1 2"
Same as for the next:
x = [1, "%i" % 2, 3]
has to be written with changed precedence as
x = [1, ("%i" % 2), 3]
So a changed precedence would have drawbacks like the current one. I
admit that the usage of % taking all following elements is more frequent.
But as you pointed out, changing it now is almost impossible. And there
is the "%" operator in numeric scope, where a list as second argument
makes no sense, as in (5%2, 2). So from my POV, the current
implementation is the best.
> > But then propose another way of making one-element
> > tuples. BTW, I don't see "(1,)" as magic, more as simple given syntax.
>
> I see the single element syntax as 'magical syntax', just like:
>
> print "foo",
>
> is magical syntax. It's just syntax that isn't very pretty as everwhere
> else the comma implies there either is another element coming or that if it's
> the last element, the comma is ignored.
That's a problem with the "plug and play" print statement of Python. It's
convinient in most cases, but makes other things very hard. The last time
I've encountered a print statement as in Python before was with my old
Sinclair Spectrum 48K and the included Basic. :)
> 'magic' (here Martijn defines magic) is where something suddenly behaves
> different in a way that's outside of an easy to predict pattern that
> holds elsewhere. It's where hard to detect subtleties can have uncommonly
> large effects. Where the mind stumbles.
>
> > Since the curly brackets {} are used for dictionaries, normal brackets []
> > for lists, there are only the parenthesis () left. And since they are
> > used for grouping, this special case for one-element tuple is needed.
> > Although I admit that I doesn't look very nice, I don't see any
> > alternatives.
>
> And the parenthesis aren't even necessary for tuples, which is nice in
> some circumstances. But in an ideal world there would be another type of
> brackets on my keyboard. :)
I can find the angles <> here on mine!
But how to handle the following? ;)
x = <1, 2>3, 4>
Or how about << >>?
Cheers, Carsten
--
Carsten Geckeler
More information about the Python-list
mailing list