Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数
Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 的区别
os.path.abspath(__file__)返回的是.py文件的绝对路径(完整路径)
os.path.dirname(__file__)返回的是.py文件的目录

import os base_path = os.path.dirname(os.path.abspath(__file__))
driver_path = os.path.abspath(__file__) print(base_path)
print(driver_path)

结果:
C:\Test_framework\test
C:\Test_framework\test\test.py
Python os.system() 函数
os的system原理
system函数可以将字符串转化成命令在服务器上运行;其原理是每一条system函数执行时,其会创建一个子进程在系统上执行命令行,子进程的执行结果无法影响主进程;
上述原理会导致当需要执行多条命令行的时候可能得不到预期的结果;
import os os.system('cd /usr/local')
os.mkdir('aaa.txt)
上述程序运行后会发现txt文件并没有创建在/usr/local文件夹下,而是在当前的目录下;
使用system执行多条命令
为了保证system执行多条命令可以成功,多条命令需要在同一个子进程中运行;
import os os.system('cd /usr/local && mkdir aaa.txt')
# 或者
os.system('cd /usr/local ; mkdir aaa.txt')
Python os.path.dirname(__file__) 与 Python os.path.abspath(__file__) 与 os.system() 函数的更多相关文章
- Python os.path.dirname(__file__) os.path.join(str,str)
Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__f ...
- Python——os.path.dirname(__file__) 与 os.path.join(str,str)
Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__f ...
- python中os.path.dirname(__file__) 命令行 参数没有绝对路径导致数据库找不到
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:/python ...
- python中的os.path.dirname(__file__)的使用
在编程时,我们要获取当前文件所在的路径,以适合所有的工程,建立相对路径. python的os.path.dirname(__file__)非常好用,建议大家使用: import os FILE = o ...
- 转: Python中的os.path.dirname(__file__)
(1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: ...
- python中的os.path.dirname与os.path.dirname(__file__)的用法
python中的os.path.dirname的用法 os.path.dirname(path) 语法:os.path.dirname(path) 功能:去掉文件名,返回目录 如: print(os. ...
- os.path.dirname(__file__)使用、Python os.path.abspath(__file__)使用
python中的os.path.dirname(__file__)的使用 - CSDN博客https://blog.csdn.net/u011760056/article/details/469698 ...
- Python模块详解以及import本质,获得文件当前路径os.path.abspath,获得文件的父目录os.path.dirname,放到系统变量的第一位sys.path.insert(0,x)
模块介绍 1.定义: 模块:用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能),本质就是.py结尾的python文件(文件名:test.py,对应的模块名:test) 包:用来从逻 ...
- python os.path.dirname() abspath()
测试文件的名称 path_test.py 先确定文件目录 (my_flask3) python@ubuntu:~/Desktop/flask_news_pro$ python path_test.py ...
随机推荐
- 经典把妹桥段:Flower dance开头对话
听到一首很赞的钢琴曲,Flower Dance,其开头有一段英文对话,如下: Lucy:"They serve the purpose of changing hydrogen into b ...
- PowerDesigner 把Comment/name 互转
转载:https://www.cnblogs.com/cxd4321/archive/2009/03/07/1405475.html 在使用PowerDesigner对数据库进行概念模型和物理模型设计 ...
- 不同修饰符使用细节(java)
常用来修饰类.方法.变量的修饰符如下 public 权限修饰符,公共访问, 类,方法,成员变量 protected 权限修饰符,受保护访问, 方法,成员变量 默认什么也不写 也是一种权限修饰符,默认访 ...
- Asp.net MVC]Asp.net MVC5系列——在模型中添加
目录 概述 在模型中添加验证规则 自定义验证规则 伙伴类的使用 总结 系列文章 [Asp.net MVC]Asp.net MVC5系列——第一个项目 [Asp.net MVC]Asp.net MVC5 ...
- Vim多行编辑
vim编辑文档有时候需要多行同时插入或者删除,比如多行加注释应该怎么操作 vim进了多行编辑模式:<ESC>之后按CTRL+V进入visual block模式(列编辑). 光标移到某行行首 ...
- Saltstack之SaltSyndic
SaltSyndic 1,SaltSyndic必须运行在salt-master上面 2,Syndic要连接另外一个Master比它更高级 在master安装syndic yum -y install ...
- Oracle体系结构之数据库启动的不同状态
数据库启动的不同状态: nomount状态:spfile和plile mount状态:control file open状态:data file和redo file 启动数据库的过程:nomount状 ...
- abi-api, arm target triplet https://en.wikipedia.org/wiki/ARM_architecture
GNU软件用target triplet来描述工作平台,target triplet是一种规范化的名称,形如cpu-vendor-os(where os can be ‘system’ or ‘ker ...
- JAVA 的wait(), notify()与synchronized同步机制
转自:http://blog.csdn.net/zyplus/article/details/6672775 在JAVA中,是没有类似于PV操作.进程互斥等相关的方法的.JAVA的进程同步是通过syn ...
- ArcGIS Server 服务器日志(待修改)
有时遇到服务相关错误,需要查看日志来排查,这里简单写下日志相关操作. 服务器日志:http://resources.arcgis.com/zh-cn/help/main/10.2/index.html ...