Created
November 22, 2011 12:27
-
-
Save ssbarnea/1385555 to your computer and use it in GitHub Desktop.
test-python-path-detection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you uncommnt
os.chdir
, the test will fail. Is there any workaround for this that is not dependent of current running directory?