New submission from Vinay Sajip: If a script is run directly, the value of __file__ in it is relative to the current directory. If run via runpy.run_module, the value of __file__ is an absolute path. This is a problem in certain scenarios - e.g. if the script is a distribution's setup.py, a lot of distributions (rightly or wrongly) assume that the __file__ in setup.py will be relative, and mess up if it's absolute.
Example: # script.py print(__file__, __name__) #runscript.py import runpy runpy.run_module('script', run_name='__main__') Example output (2.7): $ python script.py ('script.py', '__main__') $ python runscript.py ('/home/vinay/projects/scratch/script.py', '__main__') Example output (3.2): $ python3.2 script.py script.py __main__ $ python3.2 runscript.py /home/vinay/projects/scratch/script.py __main__ ---------- components: Library (Lib) messages: 177814 nosy: ncoghlan, vinay.sajip priority: normal severity: normal status: open title: Different behaviours in script run directly and via runpy.run_module type: behavior versions: Python 2.7, Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue16737> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com