[Tutor] Trying to avoid using eval..
Mitya Sirenef
msirenef at lightbird.net
Sat Feb 23 03:28:23 CET 2013
On 02/22/2013 09:11 PM, Rohit Mediratta wrote:
> Hi All,
> I want to reload my Module after I fix bugs and want to instantiate
an object of a class contained in this module.
>
> Heres the pseudo code of what I want to do:
>
> def rerun(testBlock) :
> op = testBlock.split('.')
> module = op[0] ; className = op[1]
> reload(module)
> # testBlock is a string, so it needs evaluation!
> newObject = testBlock()
>
> rerun('ModuleName.className')
>
>
> Obviously, line 4 and line 6 dont work today.
> I want to know if there is any smart way to achieve this.
> In my previous life (Tcl), I could use 'eval' or 'set' to achieve this.
>
>
> thanks,
> Rohit
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
You can do:
module = __import__(module)
-m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
"The condition of man is already close to satiety and arrogance, and
there is danger of destruction of everything in existence."
- a Brahmin to Onesicritus, 327 BC, reported in Strabo's Geography
More information about the Tutor
mailing list