New submission from Yuval S <sadan.yu...@gmail.com>:

In Python 2.7, the __package__ variable isn't set when __init__.py is run, 
until an import is done. In Python 3.5, it is set correctly.

e.g.

# mkdir x && echo "print(__package__)" | tee x/__init__.py x/test.py
# python2 x.test
None
x
# python3 x.test
x
x
# echo -e "import os\n$(cat x/__init__.py)" > x/__init__.py
# python2 x.test
x
x

This is very old, as it's there at least since 2010: 
https://stackoverflow.com/questions/4437394/package-is-none-when-importing-a-python-module
 

I would expect Python 2 and 3 to behave the same.

----------
components: Library (Lib)
messages: 354555
nosy: Yuval S
priority: normal
severity: normal
status: open
title: __package__ is None in __init__.py until an import is used
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38457>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to