LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-18-2005, 08:10 PM   #1
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Rep: Reputation: 56
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
 
Old 10-18-2005, 08:47 PM   #2
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,544
Blog Entries: 4

Original Poster
Rep: Reputation: 56
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python: Idle: ImportError: cannot import name sleep Joe Soap Linux - Newbie 1 10-01-2005 01:52 AM
Import sys ?bash: import: command not found joirnange Linux - Newbie 4 12-28-2004 10:33 PM
Creating CVS repository: cvs [import aborted]: attempt to import the repository enemorales Linux - Software 3 10-15-2004 04:30 PM
python: import distutils fails on debian? jpbarto Linux - Software 0 01-18-2004 10:36 AM
Python - can I import my own stuff? miknight Programming 1 06-10-2003 07:48 AM


All times are GMT -5. The time now is 12:08 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration