name of client module
Nick Stinemates
nick at stinemates.org
Mon Feb 18 21:52:21 EST 2008
> I'm not saying I don't want to do that. I'm saying that, in addition to
> what you've written, I want foo to know it's being imported, and by whom.
>
You're still not explaining a real example of what this could be used for.
Oh well, here's an example of an implementation of what you want to do.
Import.py
================
#!/usr/bin/python
class Importer:
def __init__(self):
pass
def __import__(self, module):
exec "import %s" % module
exec "a = %s" % module
a.setImported(self)
i = Importer()
i.__import__("Imported")
================
Imported.py
================
#!/usr/bin/python
def setImported(importer):
print "I've been imported by %s" %importer
================
--
==================
Nick Stinemates (nick at stinemates.org)
http://nick.stinemates.org
AIM: Nick Stinemates
MSN: nickstinemates at hotmail.com
Yahoo: nickstinemates at yahoo.com
==================
More information about the Python-list
mailing list