Re: Python Importing Dynamically

  • From: Haden Pike <haden.pike@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 28 Mar 2010 15:25:45 -0400

This is because you have to use a . (period) instead of a / in the line reading exec("from customizations/%s import *" % i[:-3]). It needs to be exec("from customizations.%s import *" % i[:-3]).

Haden

On 3/28/2010 3:07 PM, Storm Dragon wrote:
Hi,
The new code is:
#Dynamic Import section
customScripts = os.listdir("customizations")
for i in customScripts:
    exec("from customizations/%s import *" % i[:-3])
#end dynamic import section
I still get the syntax error:
Traceback (most recent call last):
  File "orca-customizations.py", line 16, in <module>
    exec("from customizations/%s import *" % i[:-3])
  File "<string>", line 1
    from customizations/weather import *
                       ^
SyntaxError: invalid syntax
Thanks
Storm

--
Follow me on Twitter:
http://www.twitter.com/stormdragon2976
My blog, Thoughts of a Dragon:
http://www.stormdragon.us/
What color dragon are you?
http://quizfarm.com/quizzes/new/alustriel07/what-color-dragon-would-you-be/
Install Windows Vista in under 2 minutes:
http://is.gd/am6TD

On Sun, 2010-03-28 at 14:38 -0400, Haden Pike wrote:
xec("from customizations.%s import *" % i[:-3)

Other related posts: