Issue in exec method

Posted by mukul sharma on Stack Overflow See other posts from Stack Overflow or by mukul sharma
Published on 2010-05-28T06:27:39Z Indexed on 2010/05/28 6:31 UTC
Read the original article Hit count: 324

Filed under:

Hi all,

I am a having two python files file1.py and file2.py. I am using exec() to get the method/Variables defined in the file2.py.

file1.py have a class as given below class one: def init(self): self.HOOK = None exec(file2.py) self.HOOK = Generate ### call the hook method #### self.HOOK()

file2.py looks like as (There is no class define in file2.py) def Generate() do 1 do 2 Hello()

def hello() print "hello"

Now the problem is as When i run script it is giving a error global name Hello not found. If i remove Hello() from Generate method in file2.py then its work fine. I cant use import file2.py in file1.py,because in file2.py the only one method name (Generate) is fix (its taken as requirement). So apart from Genarate method user can define any method and can call this in generate method, because this approach is not working so i have to write whole code into generate method only and code is also repetitive.

Any help is really appreciable...

© Stack Overflow or respective owner

Related posts about python