Can I import an arbitary file?

Skip Montanaro skip at pobox.com
Tue Feb 26 12:49:20 EST 2002


    Peter> What I want to do is import this file. The problem is, this file
    Peter> could be any name at all. What I want to do is parse my command
    Peter> line, and find out the name of my configuration file, and then
    Peter> import the file of that name. Is that possible?

Take a look at the execfile builtin function.  The import statement requires
the file have a basename that is a valid Python identifier, but execfile
doesn't.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list