Am 08.10.2010 10:50, schrieb Chris Withers:
> Hi All,
> 
> The new explicit relative import syntax is great.
> I wanted to relatively import a module.
> 
> import .mymoduleinmypackage
> 
> ....and got a SyntaxError in Python 2.6.
> 
> I guess I need to do:
> 
> from . import mymoduleinmypackage
> 
> ....but it does feel weirdly asymetric that:
> 
> from .mymoduleinmypackage import something
> 
> ....while:
> 
> import .mymoduleinmypackage
> mymoduleinmypackage.something
> 
> ....does not.

The explanation is that everything that comes after "import" is thereafter
usable as an identifier (or expression, in the case of dotted names) in
code.  ".mymodule" is not a valid expression, so the question would be how
to refer to it.

(This argument is weakened in the present of an "as" renaming, but I doubt
you'd like to write

import .mymodule as mymodule

.)

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to