Create a gist now

Instantly share code, notes, and snippets.

test-python-path-detection
@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.
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__))
@ssbarnea
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