Python os.path.abspath(__file__) 获取脚本完整路径
2017-12-16 16:56
489 查看
import os
import sys
print os.path.abspath(__file__)
在Python控制台下,直接使用print __file__是会导致 name ‘__file__’ is not defined错误的,因为这时没有在任何一个脚本下执行,自然没有 __file__的定义了。
import sys
print os.path.abspath(__file__)
在Python控制台下,直接使用print __file__是会导致 name ‘__file__’ is not defined错误的,因为这时没有在任何一个脚本下执行,自然没有 __file__的定义了。
相关文章推荐
- Python中获取路径os.getcwd()和os.path.dirname(os.path.realpath(__file__))的区别和对比
- Python中获取路径os.getcwd()和os.path.dirname(os.path.realpath(__file__))的区别和对比
- Python中获取路径os.getcwd()和os.path.dirname(os.path.realpath(__file__))的区别和对比
- Python中获取路径os.getcwd()和os.path.dirname(os.path.realpath(__file__))的区别和对比
- Python中获取路径os.getcwd()和os.path.dirname(os.path.realpath(__file__))的区别和对比
- Python模块详解以及import本质,获得文件当前路径os.path.abspath,获得文件的父目录os.path.dirname,放到系统变量的第一位sys.path.insert(0,x)
- python中由于中文路径引起的os.path.isfile(imgpath) == False问题
- python中的os.path.dirname(__file__)的使用
- JavaSE8基础 File getAbsolutePath 获取当前默认的工作文件夹路径
- Python_API_File and Directory Access_os.path.normcase
- C# 5.0 CallerMemberName CallerFilePath CallerLineNumber获取调用方法名称,路径,行号
- Python中的os.path.dirname(__file__)
- js获取input file完整路径的方法
- python - os.path,路径相关操作
- 通过os中的os.path.basename获取路径中的文件名
- python_20171122_python3.6.1 pd.read_csv()输入中文路径OSError: Initializing from file failed
- Python3基础 os.path.dirname 对一个路径字符串进行处理 返回路径
- python os.path.isfile()因参数问题判断错误
- 从FILE_OBJECT里获取完整NT路径和DOS路径
- python中获取打包成执行文件(exe)和脚本运行文件的路径