Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Created November 22, 2011 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssbarnea/1385555 to your computer and use it in GitHub Desktop.
Save ssbarnea/1385555 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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