views:

90

answers:

3

I have package structure that looks like this:

  • ae
    • util

util contains a method mkdir(dir) that, given a path, creates a directory. If the directory exists, no error is thrown; the method fails silently.

The directory ae and its parent directory are both on my PYTHONPATH. When I try to use this method in Python 2.6, everything is fine. However, Python 2.5 gives the following error:

util.mkdir(SOURCES)
    AttributeError: 'module' object has no attribute 'mkdir'

Why is Python 2.6 able to find this module and its method with no problems, but Python 2.5 cannot?

A: 

It depends where You call this method, and what Your import is. If You write:

from ae import util
util.mkdir(SOURCES)

everything should be ok.

The error occurs probably because of the difference in the import policy between Python 2.5 and 2.6.

Dejw
What changed from 2.5 to 2.6 with respect to import? I thought "absolute_import" (in `__future__`) was still required in 2.6, and was going to be the default only in 2.7 and 3.x.
Peter Hansen
+1  A: 

Maybe Python 2.5 is accessing a different version of util that does not have the mkdir method.

badp
+1, simplest explanation
orip
A: 
  • do you import ae.util or import util? Either ae or its parent dir should be in PYTHONPATH, but not both
  • verify you have the right util module by running print util (will print the module's source file)
orip
I was sure to place ae's parent directory in my PYTHONPATH and not ae itself. Thanks!
Wraith