public
Created

test-python-path-detection

  • Download Gist
path-tester.cmd
Batchfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
@cls
@echo --- testing ---
@echo Should all return:
@echo %~dp0
@echo.
@echo.
 
@echo #1
@cd /D %~dp0
python path-tester.py
@echo.
 
@echo #2
@cd /D %~dp0
path-tester.py
@echo.
 
@echo #3
@cd /D c:\
%~dp0path-tester.py
@echo.
 
@echo #4
@cd /D %~dp0
python -c "execfile('path-tester.py')"
@echo.
path-tester.py
Python
1 2 3 4 5 6 7 8
import sys, os, os.path, inspect
 
#os.chdir("..")
 
if '__file__' not in locals():
__file__ = inspect.getframeinfo(inspect.currentframe())[0]
 
print os.path.dirname(os.path.abspath(__file__))

If you uncommnt os.chdir, the test will fail. Is there any workaround for this that is not dependent of current running directory?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.