how can I replace a execfile with __import__ in class to use self variables

Wensheng wenshengwang at gmail.com
Wed Feb 9 20:26:17 EST 2005


I have a py program below:
--------------------------------
class someclass:
	def __init__(self):
		self.var = "hell, world"

	def printitout(self):
		execfile("printit.py")
		#__import__("printit") #doesn't work

if __name__=="__main__":
	c = someclass()
	c.printitout()
-------------------------------------------

the file printit.py has only one line:
--------------
print self.var
--------------

executing someclass works, but I can't replace execfile with import.
what globals, locals should I use to make __import__() work in that
situation?

Thank you for any help.




More information about the Python-list mailing list