Problem with imp.load_source
Kevin Smith
Kevin.Smith at theMorgue.org
Mon May 6 12:14:59 EDT 2002
I am trying to implement a new source loader using the imp.load_source()
function, but I get some weird side-effects. If I use a '.' in the
first argument of the load_source() call, classes imported in both the
main program and the imported file don't appear to be the same class
anymore. See the example below.
#------- testimp -------
#!/usr/bin/env python
import sys, imp, os
from UserList import UserList
mod = imp.load_source('my.testing',
'%(HOME)s/filters/testing.py' % os.environ)
OtherUserList = vars(mod)['UserList']
# Returns 0
print issubclass(OtherUserList, UserList)
#-------- end testimp -------
#--------- $HOME/filters/testing.py
from UserList import UserList
#--------- end testing.py -------
More information about the Python-list
mailing list