knowing a file's own name

Discussion in 'Python' started by Scott Frankel, Nov 29, 2004.

  1. 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
    Scott Frankel, Nov 29, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CodeMotion
    Replies:
    0
    Views:
    547
    CodeMotion
    Jul 3, 2003
  2. Stefan Siegl
    Replies:
    1
    Views:
    761
  3. Saverio M.
    Replies:
    0
    Views:
    500
    Saverio M.
    Jul 3, 2006
  4. Mr.M
    Replies:
    1
    Views:
    583
    Robert Kern
    Jan 29, 2010
  5. James Britt
    Replies:
    4
    Views:
    119
    Jim Weirich
    Aug 8, 2004
Loading...

Share This Page