from
Pierre Rouleau <prouleau001 at sympatico dot ca>
subject
[Python-projects] Pylint and import if __name__ == "__main__"
date
Bonjour à tous!2005/05/25 23:20
I found another issue that pylint 0.6.4 does not detect. It has to do
with the location of an import statement.
In the following test_import.py file, the ConfigParser module is,
mistakingly, imported when the file is executed as a script and
therefore the script will run properly. However, if some other module
imports test_import and tries to execute test_import.run(), then
ConfigParser will not be loaded and the program will get an exception.
The obvious solution to the problem is to move the import statement at
the beginning of the file. However, Pylint 0.6.4 does not report the
problem.
# -------------------------------------------------
# test_import.py
#
def run():
cp = ConfigParser.ConfigParser()
cp.read('some_ini_file.ini')
if 'tested' in cp.sections():
print 'tested is here'
if __name__ == "__main__":
import ConfigParser
run()
# -------------------------------------------------
--
Pierre Rouleau
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects
