doted filenames in import statements
Jean-Michel Pichavant
jeanmichel at sequans.com
Wed Jul 22 08:16:19 EDT 2009
Piet van Oostrum wrote:
>
> [snip]
>
>> JP> file = "/home/dsp/4.6.0.0/test.py"
>> JP> test = __import__(file)
>> JP> => no module name blalalal found.
>>
>
>
>> JP> Any suggestion ? I tried multiple escape technics without any success.
>>
>
> Rightly so.
>
> I think the best would be to add the directory to sys.path
> sys.path.add('/home/dsp/4.6.0.0')
> and then
> __import__('test', ... )
>
I see. My problem is that a have to import 2 different files having de
same name. In the same name space I have 2 objects from 2 different
software branches, let's say 4.6.0 and 4.6.1.
The first object shall import 4.6.0/orb.py and the second one 4.6.1/orb.py.
If I add 4.6.1 to sys.path, the import statement will look like:
self._orb = __import__('orb')
The problem is, python wil assume orb is already imported and will
assign the module from the 4.6.0 branch to my 4.6.1 object.
Do I have to mess up with sys.modules keys to make python import the
correct file ? Is there a standard/proper way to do that ?
JM
More information about the Python-list
mailing list