knowing a file's own name

S

Scott Frankel

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top