python目录的操作
2016-04-04 00:18
501 查看
python中涉及到文件路径的paths操作需要用到模块,网上许多关于os module的教程,如教程1、教程2等
本文主要对一些常用的目录操作进行简单小结
结果如下:
the value of pwd: /root/workspace/tingting/ImageProcessing
the type of pwd
结果如下:
the present working directory is: /root/workspace/tingting/ImageProcessing
the directory folder of the present working directory is: /root/workspace/tingting
可以看到,字符类型变量pwd存储的是当前运行的python/ipynb脚本文件的工作目录,而
pwd_up存储的是其上一级目录
本文主要对一些常用的目录操作进行简单小结
获取当前python/ipynb脚本的工作路径
import os pwd = os.getcwd() print 'the value of pwd:',pwd print 'the type of pwd',type(pwd)
结果如下:
the value of pwd: /root/workspace/tingting/ImageProcessing
the type of pwd
获取当前工作目录的上一级目录
import os pwd = os.getcwd() print 'the present working directory is: ',pwd pwd_up = os.path.abspath(os.path.join(pwd,os.path.pardir)) print 'the directory folder of the present working directory is: ',pwd_up
结果如下:
the present working directory is: /root/workspace/tingting/ImageProcessing
the directory folder of the present working directory is: /root/workspace/tingting
可以看到,字符类型变量pwd存储的是当前运行的python/ipynb脚本文件的工作目录,而
pwd_up存储的是其上一级目录
相关文章推荐
- python 迭代的理解
- Jupyter notebook 操作教程
- python中super 奇思妙想
- python 之二维数组
- Unix时间戳转换(python)
- python 正则表达 10分钟入门
- python学习(1)
- array与matrix
- python的socket编程
- Python多进程并发操作中进程池Pool的应用
- Python multiprocessing
- Python process
- Parsing XML in Python&Assignment
- mysql-python安装时EnvironmentError: mysql_config not found
- python shlex
- urlib2下载器网页的三种方法
- (6) Python 语句和语法 –- 条件和条件语句
- Python中创建字典的几种方法
- python版本不一致
- Python序列概述