469,352 Members | 2,150 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

dynamic attribute syntax

Hi all,
Thinking of a syntax for 'getattr' and 'setattr' dynamic access.

'obj.prop' has an easy access, but

att= 'prop'
getattr( obj, att )

is much clumsier, while no less useful, maybe more.

What are the changes, pros and cons, involved in something like:

obj:att for a dynamic access, and obj.att for static?

Snice readability is a factor, I'm open to other markings than ':'.
'$' and '?' are available, and I note that a~b, a:b, and, a!b for
identifiers 'a' and 'b' are unambiguous.

Aug 17 '08 #1
4 829
On 17 Aug, 21:29, castironpi <castiro...@gmail.comwrote:
>
What are the changes, pros and cons, involved in something like:

obj:att for a dynamic access, and obj.att for static?
A previous proposal and discussion can be found here:

http://www.python.org/dev/peps/pep-0363/

Paul
Aug 17 '08 #2
On Aug 17, 2:46*pm, Paul Boddie <p...@boddie.org.ukwrote:
On 17 Aug, 21:29, castironpi <castiro...@gmail.comwrote:
What are the changes, pros and cons, involved in something like:
obj:att for a dynamic access, and obj.att for static?

A previous proposal and discussion can be found here:

http://www.python.org/dev/peps/pep-0363/

Paul
Thanks for the reference. Well, check out the two alternatives, a~b
and a!b, which are easy on the eyes, and weren't proposed, but don't
allow expressions. (Turns out 'if a:b' is valid, so never mind that
one.) I also won't let you forget that $ and ? are unused so far
too. I see syntax was one of the complaints.

Aug 17 '08 #3
castironpi wrote:
'obj.prop' has an easy access, but

att= 'prop'
getattr( obj, att )

is much clumsier, while no less useful, maybe more.
maybe more? ok, you *are* utterly and completely unable to post
anything that makes any sense at all to anyone that uses Python.
plonkeliplonk.

Aug 17 '08 #4
On Aug 17, 3:05*pm, Fredrik Lundh <fred...@pythonware.comwrote:
castironpi wrote:
'obj.prop' has an easy access, but
att= 'prop'
getattr( obj, att )
is much clumsier, while no less useful, maybe more.

maybe more? *ok, you *are* utterly and completely unable to post
anything that makes any sense at all to anyone that uses Python.
plonkeliplonk.
More constructive contributions on both sides there. Good one.
Aug 17 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.