os库(operating system,提供操作系统函数)
常用的文件、路径
os.path.dirname(文件名字): 参数为文件名字,输出路径名,/Users/lr_work/liurong_sqls
os.path.abspath(文件名字): 参数为文件名,输出完整文件名,/Users/lr_work/liurong_sqls/run.py
os.getcwd() : 无参数,路径名字,/Users/lr_work/liurong_sqls
__file__ : 文件名字,输出/Users/lr_work/liurong_sqls/run.py
sys.argv[0]: 文件名字,输出/Users/lr_work/liurong_sqls/run.py
os.path.exists(路径名) : 返回True/False
os.path.join(路径1,路径2): 返回路径1+路径2,如果路径2的起始字符为‘/’,则返回结果为路径2
os.curdir : 输出当前路径,"."
1. __file__是什么?
ans:当前文件的名字。
例如r.py内容如下
import os
if __name__ == "__main__":
print __file__
输出结果:r.py
2. print __file__输出结果是固定的吗?
ans:不是固