Message177814
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__ |
|
Date |
User |
Action |
Args |
2012-12-20 13:37:02 | vinay.sajip | set | recipients:
+ vinay.sajip, ncoghlan |
2012-12-20 13:37:02 | vinay.sajip | set | messageid: <1356010622.32.0.479096681415.issue16737@psf.upfronthosting.co.za> |
2012-12-20 13:37:02 | vinay.sajip | link | issue16737 messages |
2012-12-20 13:37:02 | vinay.sajip | create | |
|