LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python, import and execfile() (https://www.linuxquestions.org/questions/programming-9/python-import-and-execfile-374478/)

cs-cam 10-18-2005 08:10 PM

python, import and execfile()
 
I'm working on a script, I want it to have plug-in modules in the form of Python files in the same directory, however because I'm so lazy I'm using execfile() to include the module code in the running script so I can avoid any problems with scopes etc. At this stage it's working as it should but I've run into a problem. The idea behind the plug-in modules is that they conform to an API and therefore can be written by anybody and contributed to add new functionality, sounds great doesn't it? Problem being is that obviously different "modules" are going to need different Python modules imported to be able to do their dirty work, but import statements in these files don't seem to have any effect. If I import something from the main file it works fine, but this isn't an acceptable long term solution.

I searched before posting here obviously, I found this and this but I can't seem to make them relate to my situation. It's still early in the morning but I keep drawing big fat blanks.

If anyone has any tips for ways I could get around this without resorting to importing the plug-in code in the first place I'd really appreciate it!

Thanks :)

cs-cam 10-18-2005 08:47 PM

Ok, I'm an idiot. Chucking import statements at the top of the file doesn't work, but if I put the import inside a method of the object in the file it works. All the works gets done in the update() method so put the required imports at the top of that and we're all sweet now :D


All times are GMT -5. The time now is 04:42 AM.