[Tutor] Problem on select esecution of object in a class

Peter Otten __peter__ at web.de
Wed Aug 5 19:01:31 CEST 2015


jarod_v6--- via Tutor wrote:

> I have a class with many objects and I want to  select using opt parse
> some function id = options.step
>         ena = Rnaseq(options.configura, options.rst, options.outdir)
>         now = datetime.datetime.now()
>         ena.show()
>         diz = {}
>         for i,t in enumerate(ena.steps()):
>             diz.setdefault(i,[]).append(t.__name__)
>         
>         for i in "ena."+"".join(diz[id])+"()":
> 
>             print i.command
> 
>  1 for i in "ena."+"".join(diz[id])+"()":
>       2
> ----> 3                 print i.command
>       4
> 
> AttributeError: 'str' object has no attribute 'command'
> 
> 
> here you se what they ouptut
> "ena."+"".join(diz[id])+"()"
> Out[85]: 'ena.trimmomatic()
> 
> Definition: ena.trimmomatic(self)
> Source:
>         def trimmomatic(self):

[...]

> Any suggestion in how to choose the function to use?

If I understand you correctly you want getattr():

ena = Rnaseq(options.configura, options.rst, options.outdir)
method = getattr(ena, options.step)
method()




More information about the Tutor mailing list