Re: why _import__ only works from interactive interpreter?

2006-05-08 Thread [EMAIL PROTECTED]
You are absolutely right, it's that empty entry that allows the absolute path to work. I'll probably add the path to sys.path, but as this is only a config file from which I need just a few vars, I'll try to use execfile, looking in past threads it looks like a better option for this use, I really

Re: why _import__ only works from interactive interpreter?

2006-05-08 Thread [EMAIL PROTECTED]
Sorry to follow up myself, I've finally used the execfile approach, passing an empty dict for capturing locals and then just processing it: new_settings = {} execfile(self.SETTINGS_MODULE, new_settings) # returns its locals in new_settings # assign UPPER_CASE vars for setting in

why _import__ only works from interactive interpreter?

2006-05-07 Thread [EMAIL PROTECTED]
I don't know what I'm doing wrong, but the result is that _import_ only works from a python shell, but not when I call a python script. $ cat test.py mod = __import__(/home/me/tests/test_imp) Called from a script it does not work: $ python /home/me/test.py Traceback (most recent call last):

Re: why _import__ only works from interactive interpreter?

2006-05-07 Thread BartlebyScrivener
I'm on Windows, but I think you need the shebang thing at the top of your script, right? Then, put whatever you want to import in a script or module called testmod.py. Then you should be able to import either into a script or at the command line using simply: import testmod If it doesn't work

Re: why _import__ only works from interactive interpreter?

2006-05-07 Thread [EMAIL PROTECTED]
It's not that, it looks like __import__looks into sys.path, so if use an absolute path it cannot work. I found this thread and it seems they are right:

Re: why _import__ only works from interactive interpreter?

2006-05-07 Thread I V
On Sun, 07 May 2006 16:21:01 -0700, [EMAIL PROTECTED] wrote: So, if this is right, I need to put the .py file to be imported inside sys.path!! And the relative path will be usedto find the module. Can I __import__ providing the absolute path? import sys print sys.path ['',