[summerofcode] Problem in import

John Xiaogang Zhang xiaogang at gridmo.com
Thu Jul 14 11:08:32 CEST 2005


Hi all,

I am a newbe in Python, and sometimes have problem with import.

Now I have a line

    from tilefilesys.tilefile import TFHandlers

in the top level module test.py. I have also tried to use

    import tilefilesys.tilefile.TFHandlers as TFHandlers

but the behaviour seems exactly the same.

The code in test.py calls other modules, some of them also use the 
similar import statement, and I got the following error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "test.py", line 29, in test
    from tilefilesys.tilefile import TFHandlers
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/TFHandlers.py", line 
28, in ?
    from tilefilesys.tilefile.FmtVersn import *
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/FmtVersn.py", line 163, 
in ?
    defaultVersnModule = loadTFModule( defaultVersionStr )
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/FmtVersn.py", line 156, 
in loadTFModule
    return dynImport(__baseTFPackage + __availableVersions[versnStr])
  File "/home/xzhang/dev/TS/tilefilesys/common.py", line 401, in dynImport
    mod = __import__(modName, globals(), locals(), [])
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/v1/__init__.py", line 
26, in ?
    import TFs
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/v1/TFs.py", line 27, in ?
    from Fields import *
  File "/home/xzhang/dev/TS/tilefilesys/tilefile/v1/Fields.py", line 33, 
in ?
    from tilefilesys.tilefile import TFHandlers
ImportError: cannot import name TFHandlers


If I change the line in the last file (Fields.py) to

    import tilefilesys.tilefile.TFHandlers as TFHandlers

then the error becomes

  File "/home/xzhang/dev/TS/tilefilesys/tilefile/v1/Fields.py", line 32, 
in ?
    import tilefilesys.tilefile.TFHandlers as TFHandlers
AttributeError: 'module' object has no attribute 'TFHandlers'

However, if I change the last file to

    import tilefilesys.tilefile.TFHandlers as TFHandlers

that is, without the "as TFHandlers", then the errors gone (but I cannot 
refer it as the shorter reference).

Could please anyone tell me why it happens, and how to get rid off it?

Thank you in advance.

Xiaogang


More information about the summerofcode mailing list