[Tutor] importing variables
Stefan Lesicnik
stefan at lsd.co.za
Thu Nov 12 17:34:56 CET 2009
On Thu, Nov 12, 2009 at 6:26 PM, bob gailer <bgailer at gmail.com> wrote:
> Stefan Lesicnik wrote:
>>
>> Hi guys,
>>
>> Im trying to do something and hit a bit of a wall, potentially im
>> going about this the wrong way. Essentially the problem is:
>>
>> features file contains
>> rt='''text'''
>>
>> import features
>>
>> a = 'rt'
>> print features.rt #this works
>> print features.a #this fails
>>
>> I need to use features.a as i am iterating through a list and a would
>> be the different features i want to check if they exist, and then use
>> the variable.
>>
>> I hope that makes sense, or if anyone has any suggestion on how
>> properly to do this!
>>
>
> Even though Alan missed your point, I understood it. So your explanation was
> OK (for me).
>
> print getattr(features, a)
Thanks Bob!
That works. I hadn't heard about getattr
Much appreciated
stefan
More information about the Tutor
mailing list