how to pass attribute name via sys.argv

Felix Hebeler zuerich at hebeler.net
Thu Jan 27 11:20:21 EST 2005


Wolfram Kraus wrote:
> Felix Hebeler wrote:
> 
<snip>
>>
>> I need to call an object attribute:
>>
>> value = object.attrName[0]
>>
<snip>
> 
> Use getattr:
> value = getattr(object, attrName)[0]
> 

> 
> 
> HTH,
> Wolfram

Thanks so much!
Had I known earlier.
Looks so easy...

Now, why did I not find this in the online tutorial, the reference 
manual, or google?
Not that I didn't try... I mean, I would find 'getattr' if I searched, 
but if you don't know what you're looking for..

I find the reference manual extremely (== too) compact to look things up.
A couple of colleages and me agreed that it is much more difficult to 
find solutions and _useful_ tips for Python than e.g. for Java (where 
there's  Javadoc for example). The syntax doc in the reference manual to 
me looks like computer linguists might understand, but unfortunately not 
me. And Python code IS really easy to read, I agree, but what if I can't 
find out how to write it?
I'd appreciate any link to online resources or recommendations for books 
(english/german)!

Chances are I'm a silly/lazy/deprived/stupid bugger, but I try to think 
there's still hope!

again, thank you so much for your quick response (thanks Gilles Lenfant 
too!), I really DO like the Python community ;-)

Cheers
Felix



More information about the Python-list mailing list