Python: how to import a python file that doesn't end in .py?
Not sure if I'm overcomplicating things, but...
I need to import a python class that's defined in a file that does not end in .py (it has no extension). I'm guessing that the lack of .py extension is why I can't simply add the path and import. Is there another way to import? Can I read the whole file into a var & exec that var? Is there some other way? Thanks |
it not difficult to name it with a .py extension.
|
Quote:
for anyone interested in how to actually solve this problem, here's what I've done: Code:
mp4_script = 'path/to/python/script' |
You could use execfile (see http://docs.python.org/lib/built-in-funcs.html)
|
Quote:
Code:
# mv /path/to/python/script /path/to/python/lib/myscript.py |
Quote:
I could copy it somewhere, yes. I could put a symbolic link somewhere, yes. Solutions like that, however, clutter up the file system with copies of files that could be used otherwise. ntubski: thanks for execfile. that looks a little cleaner. |
All times are GMT -5. The time now is 03:32 PM. |