Created
August 17, 2014 14:38
-
-
Save hanxiaomax/8e6545ec51f0c580e1ed to your computer and use it in GitHub Desktop.
1.取路径 2.glob取父级目录 3.sys.argv[0]和__file__的区别
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
from sys import argv | |
import sys | |
import glob | |
import os | |
script=argv | |
print os.path.abspath(sys.argv[0])#使用__file__时,命令行和直接运行结果不同,不明白 | |
path=os.path.abspath(sys.argv[0]) | |
#这里sys.argv[0]得到的是相对路径,需要取一下绝对路径 | |
print type(path) | |
print path+r"../*.md" | |
print glob.glob(path+r"\../*.md")#获取父级目录,注意\和/的用法 |
虽然取父级目录可以实现功能,但是打印的时候,不够直观
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
注意,如果不适用r前缀,则输出会不正确。路径也可能会被转义符号干扰