I'm looking for a way to identify a filename remotely. Put differently, is there a way a file can get its own name from its globals()?

doit.py calls exec() on a second py script, tpairs.py, to obtain a dict of the
globals in tpairs.py. How can I add the filename, "tpairs.py," to the resulting dict?
i.e.:


# - - - - - - - - - - - - - - - -
# -- tpairs.py
# - - - - - - - - - - - - - - - -
this  = "this"
that  = "that"
gdict = globals()

# - - - - - - - - - - - - - - - -
# -- doit.py
# - - - - - - - - - - - - - - - -
#!/usr/bin/env python

theFile = "./tpairs.py"
theDict = {}
execfile(theFile, theDict)

# somehow add theFile to gdict, i.e.:
# gdict['theFile'] = theFile


Thanks in advance! Scott

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to