django - how to make python __FILE__ display symbolic path when accessed use symbol path -
the __file__ convenient macro designed access current file path in python. there's issue when use it. have file /home/a/b.py when accessed directory __file__ macro in b.py should give /home/a/b.py
correct. created symbol link under /var/www/a -> /hom/a when b.py accessed /var/www/a expect macro in b.py give path /var/www/a/b.py
. not case. although file accessed form symbol path /var/www/a, macro still giving real file path /home/a/b.py
i've tried abspath , realpath in python os package. there api can peel out symbolic path wanted?
you can use first argument command line if script called full path. here's example ran:
import sys print(sys.argv)
from command line:
python test.py # results in ['test.py'] python /full/path/test.py # results in ['/full/path/test.py']
Comments
Post a Comment