dynamic attribute syntax

C

castironpi

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.
 
F

Fredrik Lundh

castironpi said:
'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.
 
C

castironpi

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.
 
C

castironpi

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top