472,119 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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 853
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 Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.