Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

test-python-path-detection

View path-tester.cmd
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.
View path-tester.cmd
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__))
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.