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/2010-July/102581.html below:

[Python-Dev] unexpected import behaviour

[Python-Dev] unexpected import behaviour [Python-Dev] unexpected import behaviourAlexander Belopolsky alexander.belopolsky at gmail.com
Sat Jul 31 03:21:05 CEST 2010
On Fri, Jul 30, 2010 at 2:46 PM, Daniel Waterworth
<da.waterworth at gmail.com> wrote:
..
> Having thought it through thoroughly, my preference is for a warning.
>
> I don't think it's a good practise to import the __main__ module by
> filename, as renaming the file will break the code. I got stung after,
> having dropped into a python interpreter shell and imported the
> module, I executed a function that uses isinstance.
>
> If a warning showed up after importing the module, explaining the
> problem and suggested that I use __import__('__main__') instead, I
> would have saved myself a fair amount of time debugging code. This is
> another case of "Explicit is better than implicit.".


You can easily disallow importing __main__ module by filename by
simply giving your script a name that does not end with .py or by
using say '-' character in the filename.   No change to python itself
is needed.
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