Relative imports in Python 3.0

Nicholas nicholas.cole at
Wed Dec 17 11:01:17 CET 2008

Imagine a module that looks like


In python 2.x I used to have tests at the end of each of my modules,
so that module might look something like

import a

if __name__ == '__main__':

But under Python 3.0 this seems impossible.  For usual use import
has to become the line:

from . import a

But if I use that form it is no longer possible to run as a
standalone script without raising an error about using relative

I am sure I am not the first to run into this issue, but what is the

Best wishes,


More information about the Python-list mailing list