from
Sylvain Thénault <sylvain.thenault at logilab dot fr>
to
Pierre Rouleau <prouleau001 at sympatico dot ca>
subject
Re: [Python-projects] Pylint and import if __name__ == "__main__"
date
On Wednesday 25 May à 23:20, Pierre Rouleau wrote:2005/05/26 10:08
> Bonjour à tous!
Bonjour,
> 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()
>
> # -------------------------------------------------
Thanks Pierre, I've added this feature request to the pylint tracker.
regards
--
Sylvain Thénault LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects
