python开发_os.path
在python中,os.path模块在处理路径的时候非常有用
下面是我做的demo
运行效果:
=========================================
代码部分:
=========================================
#python os import os def abspath(path):
'''Return a normalized absolutized version of the pathname path'''
return os.path.abspath(path) def dirname(path):
'''Return the directory name of pathname path'''
return os.path.dirname(path) def getatime(path):
'''Return the time of last access of path'''
return os.path.getatime(path) def gettime(path):
'''Return the time of last modification of path'''
return os.path.gettime(path) def getsize(path):
'''Return the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible.'''
return os.path.getsize(path) def is_file(path):
'''Return True if path is an existing regular file.
This follows symbolic links, so both islink() and isfile()
can be true for the same path.'''
return os.path.isfile(path) def is_dir(path):
'''Return True if path is an existing directory. This follows symbolic links,
so both islink() and isdir() can be true for the same path.'''
return os.path.isdir(path) def is_link(path):
'''Return True if path refers to a directory entry that
is a symbolic link. Always False if symbolic links are not supported.'''
return os.path.islink(path) def splitext(path):
'''
Split the pathname path into a pair (root, ext) such that
root + ext == path, and ext is empty or begins with a period
and contains at most one period. Leading periods on the basename
are ignored; splitext('.cshrc') returns ('.cshrc', '').
'''
return os.path.splitext(path) def splitunc(path):
'''
Split the pathname path into a pair (unc, rest) so that unc is
the UNC mount point (such as r'\\host\mount'), if present,
and rest the rest of the path (such as r'\path\file.ext').
For paths containing drive letters, unc will always be the
empty string.
'''
return os.path.splitunc(path) def split(path):
'''Split the pathname path into a pair, (head, tail) where tail is the last
pathname component and head is everything leading up to that'''
return os.path.split(path) def main():
path_file = 'C:\\test.html'
path_dir = 'C:\\Windows\\Branding'
print(abspath(path_file))
print(dirname(path_dir))
print(getatime(path_file))
print(getsize(path_file))
print(splitext(path_file))
print(splitunc(path_file))
print(split(path_file)) if __name__ == '__main__':
main()
python开发_os.path的更多相关文章
- 【Machine Learning】Python开发工具:Anaconda+Sublime
Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...
- ubuntu上用eclipse搭建java、python开发环境
上一篇文章讲到如何在windwos上用eclipse搭建java.python开发环境,这一讲将关注如何在ubuntu上实现搭建,本人使用虚拟机安装的ubuntu系统,系统版本为:14.04 lts ...
- windows 下用eclipse搭建java、python开发环境
本人只针对小白!本文只针对小白!本文只针对小白! 最近闲来无事,加上之前虽没有做过eclipse上java.python的开发工作,但一直想尝试一下.于是边查找资料边试验,花了一天时间在自己的机器上用 ...
- kali linux Python开发环境初始化
kali linux Python 黑客编程1 开发环境初始化 为什么要选择Python? Python作为目前Linux系统下最流行的编程语言之一,对于安全工作者的作用可以和C++相提并论.Pyth ...
- Sublime搭建Python开发环境
print ('hello world!') 1. 下载python,并设置path系统环境变量:当在命令行中输入python,出现如下界面,显示安装成功. 2. 安装最新的sublime,使用注册机 ...
- SublimeText3下的Python开发环境配置
最近重装了机器,需要重新安装Python的开发环境,中间遇到了几个问题,特些记录一下,以防下次备忘. 从Python的网站下载安装Python,这个非常简单,没有什么值得说的,大家可以参考廖雪峰的这个 ...
- Python开发【第六篇】:模块
模块,用一砣代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合.而对于一个复杂的功能来,可能需要多个函数才 ...
- Python开发【第二篇】:初识Python
Python开发[第二篇]:初识Python Python简介 Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏 ...
- 翻译:打造基于Sublime Text 3的全能python开发环境
原文地址:https://realpython.com/blog/python/setting-up-sublime-text-3-for-full-stack-python-development/ ...
随机推荐
- idea docker 连接 linux 上的 docker
安装插件 Docker插件,首先需要在你的IDEA中安装Docker插件,定位到File-Setting-Plugins后搜索Docker Integration安装 配置Docker服务器,在IDE ...
- 导航狗IT周报-2018年05月27日
原文链接:https://www.daohanggou.cn/2018/05/27/it-weekly-9/ 摘要: “灰袍技能圈子”将闭圈:物理安全:为什么我们现在的生活节奏越来越快? 技术干货 1 ...
- fileIO和OS操作文件和目录
1.FileIO操作文件 # 文件IO,读取文件和创建文件 # 1.读取键盘输入 x=input("please input number") print("您输入的是& ...
- jquery对象和javascript对象即DOM对象相互转换
jquery对象和javascript对象即DOM对象相互转换 1. DOM 对象转成 jQuery 对象对于已经是一个 DOM 对象,只需要用 $() 把DOM对象包装起来,就可以获得一个 jQue ...
- 工具===激活xmind 8
[下载jar包]: https://stormxing.oss-cn-beijing.aliyuncs.com/files/XMindCrack.jar 方法: 打开xmind 8 安装目录的 ...
- 64_p9
python2-termcolor-1.1.0-11.fc26.noarch.rpm 12-Feb-2017 14:05 13610 python2-terminado-0.6-2.fc26.noar ...
- 动态更新echart成交量柱状图,并且不重绘,类似K线的更新方式
function setoption(data) { let dataVolume=volumeChartData; var option = { title: { text: '成交量',// su ...
- postman中 form-data、x-www-form-urlencoded、raw、binary的区别 && 下载文件
1.form-data: 就是http请求中的multipart/form-data,它会将表单的数据处理为一条消息,以标签为单元,用分隔符分开.既可以上传键值对,也可以上传文件.当上传的字段是文件 ...
- cgi与html相互调用
html中调用cgi.<form action="/cgi-bin/mult.cgi" method="get" target="_blank& ...
- 转:win32下的堆管理系统
转:https://bbs.pediy.com/thread-224136.htm 准备刷漏洞战争中的堆溢出部分,但是对于堆的了解较少,在这里记录一下关于堆的学习记录,有错误请各位大大拍砖 参考: & ...