[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

pythonpath

luca72

3/1/2010 10:49:00 AM

Sorry for my stupid question if i have to load module from a folder i
have to append it to the sys path the folder?
ex:
if my folder module is /home/lucak904/Scrivania/Luca/enigma2
i do this :
import sys
sys.path.append('/home/lucak904/Scrivania/Luca/enigma2')
If this is correct why when i write:
form enigma2 import *
i get no module named enigma2

Thanks
Luca

I'm under linux


1 Answer

marduk

3/1/2010 12:14:00 PM

0

On Mon, 2010-03-01 at 02:48 -0800, luca72 wrote:
> Sorry for my stupid question if i have to load module from a folder i
> have to append it to the sys path the folder?
> ex:
> if my folder module is /home/lucak904/Scrivania/Luca/enigma2
> i do this :
> import sys
> sys.path.append('/home/lucak904/Scrivania/Luca/enigma2')
> If this is correct why when i write:
> form enigma2 import *
> i get no module named enigma2

There are two reasons for this:

1. enigma2 is not in your namespace. What's inside enigma is. For
example, you can't say "from site-packages import *" because
Python doesn't look at "site-packages". It looks at what's
inside site-packages. If you wanted" enigma2" to be in your
namespace, you should add /home/lucak904/Scrivania/Luca" to your
system path.
2. Even if you did above, it may not work because enigma2 is a
directory. Remember "from x import *" only works for modules and
packages, so if you want "enigma2" to be a package, remember to
add an (empty) __init__.py to the directory.

Hope this helps.
-a