[Tutor] importing variables

bob gailer bgailer at gmail.com
Thu Nov 12 17:26:39 CET 2009


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)



-- 
Bob Gailer
Chapel Hill NC
919-636-4239


More information about the Tutor mailing list