Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
1.取路径 2.glob取父级目录 3.sys.argv[0]和__file__的区别
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")#获取父级目录,注意\和/的用法
@hanxiaomax

This comment has been minimized.

Copy link
Owner Author

hanxiaomax commented Aug 17, 2014

注意,如果不适用r前缀,则输出会不正确。路径也可能会被转义符号干扰

@hanxiaomax

This comment has been minimized.

Copy link
Owner Author

hanxiaomax commented Aug 17, 2014

虽然取父级目录可以实现功能,但是打印的时候,不够直观

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.