Ciao, Sto scrivendo un programma che aggiorna il sys.path e controlla che una certa libreria sia diventata importabile.
Nella mia home (sono su linux) ho creato una cartella strutturata nel seguente modo: {{{ $ mkdir -p testlib/libgreen $ touch testlib/libgreen/test0.py $ touch testlib/libgreen/test1.py $ mkdir -p testlib/libhydro $ touch testlib/libhydro/test2.py $ touch testlib/libhydro/test3.py $ tree testlib testlib ├── libgreen │ ├── test0.py │ └── test1.py └── libhydro ├── test2.py └── test3.py 2 directories, 4 files }}} ora se provo ad eseguire il seguente codice da python 3 funziona e da python 2 no... voi sapete dirmi perchè? il codice è: {{{ # -*- coding: utf-8 -*- # file: test.py import sys sys.path.append('testlib') import libgreen print('Done!') }}} eseguendolo da shell ottengo {{{ $ python3 test.py Done! $ python2 test.py Traceback (most recent call last): File "test.py", line 5, in <module> import libgreen ImportError: No module named libgreen }}} E perchè la funzione "imp.find_module" da errore in entrambe le versioni? codice: {{{ # -*- coding: utf-8 -*- # file: test_imp.py import imp import sys sys.path.append('testlib') imp.find_module('libgreen') print('Done!') }}} shell: {{{ $ python3 test_imp.py Traceback (most recent call last): File "test_imp.py", line 6, in <module> imp.find_module('libgreen') File "/usr/lib/python3.5/imp.py", line 296, in find_module raise ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named 'libgreen' $ python2 test_imp.py Traceback (most recent call last): File "test_imp.py", line 6, in <module> imp.find_module('libgreen') ImportError: No module named libgreen }}} cosa sto sbagliando? come posso risolvere? idee? Buona serata. Pietro _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python