python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别
来源:互联网 发布:软件汉化教程 编辑:程序博客网 时间:2024/06/04 08:50
os.path.realpath
获取当前执行脚本的绝对路径。
os.path.realpath(__file__)
os.path.cwd()
获取当前脚本的所在路径
脚本一:
所在路径:
/Users/wangxiansheng/Documents/Pycharm/PyMySQL/insert_sql.py
import osdef getpath(): file = os.path.realpath(__file__) print('insert_sql file:', file) cwd = os.getcwd() print('insert_sql cwd:', cwd)
insert_sql file: /Users/wangxiansheng/Documents/Pycharm/PyMySQL/insert_sql.pyinsert_sql cwd: /Users/wangxiansheng/Documents/Pycharm/PyMySQL
脚本二:
所在路径:
/Users/wangxiansheng/Documents/Pycharm/christian/cia.py
from PyMySQL import insert_sqlimport osinsert_sql.getpath()path = os.getcwd()print('cia cwd', path)file = os.path.realpath(__file__)print('cia file:', file)
insert_sql file: /Users/wangxiansheng/Documents/Pycharm/PyMySQL/insert_sql.pyinsert_sql cwd: /Users/wangxiansheng/Documents/Pycharm/christiancia cwd /Users/wangxiansheng/Documents/Pycharm/christiancia file: /Users/wangxiansheng/Documents/Pycharm/christian/cia.py
结论:
- realpath() 获得的是该方法所在的脚本的路径
- cwd,获得的是当前执行脚本的所在路径,无论从哪里调用的该方法。
阅读全文
0 0
- python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别
- os.getcwd()和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.path.realpath(__file__),os.getcwd(),sys.path() 的区别
- os.path的方法
- __file__,os.path,sys.path细节整理
- os 和os.path 区别及使用
- python3 os.path 模块常用方法汇总
- os.mkdir()和os.path.join()的区别
- os.mkdir()和os.path.join()的区别
- os.mkdir()和os.path.join()的区别
- os,os.path属性和方法列表
- Python的os和os.path模块
- python的os和os.path模块
- python中os.path.dirname(__file__)的使用
- python中os.path.dirname(__file__)的使用
- python中os.path.dirname(__file__)的使用
- 前端秋招总结[一]
- MPI之数据类型
- aqua datastudio配置
- php并于nginx整合
- 100亿个query,1G内存如何找出这俩个文件的交集?分别给出近似算法和精确算法?
- python3 os.path.realpath(__file__) 和 os.path.cwd() 方法的区别
- Hibernate:doInHibernate
- ajax之async属性
- 关于web项目sessionID欺骗的问题
- 最小二乘法与最优线性滤波
- 使用MapReduce开发WordCount应用程序
- maven实用
- ARM处理器模式切换(含MRS,MSR指令)
- Java的输入输出