* Colin Brown [Tue, 25 Nov 2003 11:30:24 +1300]:
My experience with Python is not that large but I'll try to help:
I have instances where Python 2.3.2 import both does not work or error. It
can be demonstrated under Win2k and Linux by doing the following:
1. Create a subdirectory "abc"
2. In directory "abc" create a blank "__init__.py"
3. In directory "abc" create a file "abc.py" containing "print 'this is
abc'"
4. Interactively run python interpreter import sys
sys.path.append('./abc')
import abc
It sometimes works for me (in similar situations) if you do:
5. Interactively run python interpreter import sys
sys.path.insert(0,'./abc')
import abc
this is abc
The first (default) entry in sys.path is '', which means (I think) the
current directory. So sys.path.append('./abc') appends after this entry;
then, on "import abc", python uses first '' entry, which means it looks
under current directory where it finds "abc" which gets imported *as a
module*.
But, if you place './abc' before '', python will look first *inside*
./abc, considering it a plain directory and not a module. There, under
./abc, it is abc.py, which gets imported by the second "import abc", and
*executed*.
--
Adeodato Simó (a.k.a. thibaut)
EM: asp16 [ykwim] alu.ua.es | IM: my_dato [jabber.org] | PK: DA6AE621
To be nobody but yourself in a world which is doing its best night and
day to make you like everybody else means to fight the hardest battle
any human being can fight and never stop fighting.
-- e.e. cummings
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iEYEARECAAYFAj/CjHkACgkQTxqZjtpq5iHhzQCg39rtrQ8Y8r2p4U9Yaxus5QPK
/gEAn1domZ9yj1PhFU/OnIcTqbu4b19g
=ci2/
-----END PGP SIGNATURE-----