[Tutor] Trying to avoid using eval..
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 ; className = op
> # testBlock is a string, so it needs evaluation!
> newObject = testBlock()
> 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.
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
You can do:
module = __import__(module)
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