Python language suggestion

Chris Ryland cpr at emsoftware.com
Sat Jan 13 12:47:36 EST 2001


In article <93pu3g$cem$1 at newshost.accu.uu.nl>,
  m.faassen at vet.uu.nl (Martijn Faassen) wrote:
>
> Anyway, if the proposal is what Andrew is suggesting, it's an
interesting
> idea, which I'm mulling over too. I don't know..
>
> One problem seems to be the string methods. What happens here?
>
> foo.' bar '.strip()

The foo.' bar ' resolves first and is evaluated, then the .strip()
method is called on the result. Shouldn't be confusing, though perhaps
visually it is.

> Also, where does it end? After all, not only strings can be used as
> dictionary keys:
>
> foo.1 = 2
>
> Though I just checked and setattr() certainly doesn't accept:
>
> settattr(a, 1, "foo")
>
> It does work through __dict__ though:
>
> a.__dict__[1] = "foo"
>
> print a.__dict__[1]
>
> But this seems to be of limited applicability; getattr only takes
strings
> too. :)

I wouldn't push it that far--the only point is syntactic sugar for
attributes whose names don't quite cut it lexically (reserved words,
embedded spaces, punctuation, etc.).

To me, document.page[1].textrun[0].'text style info' is much clearer
than document.page[1].textrun[0]['text style info']--you're clearly
selecting an object attribute, not just looking up something in a
dictionary.

I.e., it raises the level of discussion one whole abstraction.

That's the only reason I'm proposing it. As pure syntactic sugar, it's
probably not worth it. I think it adds something to the clarity of
expression.
--
Chris Ryland * Em Software, Inc. * www.emsoftware.com


Sent via Deja.com
http://www.deja.com/



More information about the Python-list mailing list