Files, directories and imports - relative to the current directory only

ptn tn.pablo at
Tue Mar 25 17:27:58 CET 2008

Hello, group.

I can only read files and import modules that are in the same
as the one my script is.  Here is a test script (

	import os
	import uno  # some module I wrote

	print list(os.walk('~/hacking/python'))
	f = open('~/read/foo.txt')

And here is the output:

	Traceback (most recent call last):
	  File "", line 2, in <module>
		import uno
	ImportError: No module named uno

If I comment that import, the output becomes this:

	Traceback (most recent call last):
	  File "", line 4, in <module>
		f = open('~/read/foo.txt')
	IOError: [Errno 2] No such file or directory: '~/read/foo.txt'

(Notice the empty list at the beginning, that would be the output of

I have added this line to my .bashrc:
export PYTHONPATH=$PYTHONPATH:~/hacking/python
I thought that by doing so all the scripts found in that directory and
all it's children would be available for import, but that doesn't seem
to be the case.  As for the other problems, I have no idea.

So, what's wrong here? Maybe there's something I haven't set up?

More information about the Python-list mailing list