A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-January/041754.html below:

[Python-Dev] Dots in __name__ break import -- fixable?

[Python-Dev] Dots in __name__ break import -- fixable? [Python-Dev] Dots in __name__ break import -- fixable?Guido van Rossum guido at python.org
Tue Jan 6 18:18:00 EST 2004
> There must be some code in the import machinery that assumes (with 
> excellent reason) that the __name__ of the module from which it is 
> called will never contain periods.

Right.  Periods in module names are used for the package namespace.
(Import some code that uses packages and then print sys.modules.keys()
to see how.)

> Consider the following:
> 
>  >>> __name__ = 'a.b.c'
>  >>> import string
>  >>> string
> <module 'a.b.string' from '/usr/lib/python2.3/string.pyc'>
> 
> The peculiar behavior is *only* triggered by periods:
> 
>  >>> __name__ = ''.join(map(chr, range(1, 256))).replace('.', '')
>  >>> import string
>  >>> string
> <module 'string' from '/usr/lib/python2.3/string.pyc'>
> 
> Would this be easy to fix?

No.

> It would fall into the realm of "so don't do that!" except that Zope's 
> Python Scripts set their __name__ to their Zope Id, which can contain 
> periods.

Too bad.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4