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()


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to