Cool object trick
Alex Stapleton
alexs at advfn.com
Fri Dec 17 05:12:19 EST 2004
More information about the Python-list mailing list
Fri Dec 17 05:12:19 EST 2004
- Previous message (by thread): create lowercase strings in lists - was: (No subject)
- Next message (by thread): Cool object trick
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Steven Bethard wrote: > Alex Stapleton wrote: > >> you are setting the variable name in your code (b.varA), not >> generating the variable name in a string (var = "varA") (dictionary >> key) at run-time and fetching it from the __dict__ like i was >> attempting to describe. > > > Ahh. Well if you just want to get an attribute, I don't see why you > wouldn't do it the normal way: > > >>> b = Bunch(varA="Hello!") > >>> getattr(b, "varA") > 'Hello!' > > That's what getattr's for. ;) No need to go poking around in __dict__. > > Steve Hmm true, (i had forgotten about getattr :/) in that case im indifferent to Bunch() not that i really see why it's useful except for making code look a bit nicer occasionaly.
- Previous message (by thread): create lowercase strings in lists - was: (No subject)
- Next message (by thread): Cool object trick
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list