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/ ...
随机推荐
- java网络编程三次握手四次挥手
第一次握手:client设置syn=1,随机产生一个序列号seq=x,将数据包发送到server.client进入syn_send状态, 等待server确认. 第二次握手:server查看clien ...
- UTF-8和GB2312互转的最简单快捷的方法
一.如果你想把utf-8转为GB2312 1.用记事本打开源码,把<meta http-equiv="Content-Type" content="text/htm ...
- mysql的两种存储引擎
MySQL 有多种存储引擎,目前常用的是 MyISAM 和 InnoDB 这两个引擎,除了这两个引擎以为还有许多其他引擎,有官方的,也有一些公司自己研发的.这篇文章主要简单概述一下常用常见的 MySQ ...
- mongo备份&恢复
1.备份数据: $mongodump -h 127.0.0.1 -u traderaccount -p kasumi -d traderaccount -o "/traderaccount& ...
- [你必须知道的.NET]第二十回:学习方法论
说在,开篇之前 本文,源自我回答刚毕业朋友关于.NET学习疑惑的回复邮件. 本文,其实早计划在<你必须知道的.NET>写作之初的后记部分,但是因为个中原因未能如愿,算是补上本书的遗憾之一. ...
- DotNetOpenAuth实践系列
写在前面 本人在研究DotNetOpenAuth的过程中,遇到很多问题,很多坑,花费了很多时间才调通这玩意,现在毫无保留的分享出来,希望博友们可以轻松的上手DotNetOpenAuth,减少爬坑时间. ...
- C# HTML 生成 PDF
原文出处:http://www.cnblogs.com/shanyou/archive/2012/09/07/2676026.html
- 【洛谷】P4585 [FJOI2015]火星商店问题
题解 题目太丧,OJ太没有良心,我永远喜欢LOJ! (TLE报成RE,垃圾洛谷,我永远喜欢LOJ) 好的,平复一下我debug了一上午崩溃的心态= =,写一写这道题的题解 把所有限制去掉,给出一个值, ...
- 什么是泛型 转载自http://www.blogjava.net/Jack2007/archive/2008/05/05/198566.html
我们在编写程序时,经常遇到两个模块的功能非常相似,只是一个是处理int数据,另一个是处理string数据,或者其他自定义的数据类型,但我们没有办法,只能分别写多个方法处理每个数据类型,因为方法的参数类 ...
- 洛谷P2657 [SCOI2009]windy数 [数位DP,记忆化搜索]
题目传送门 windy数 题目描述 windy定义了一种windy数.不含前导零且相邻两个数字之差至少为2的正整数被称为windy数. windy想知道, 在A和B之间,包括A和B,总共有多少个win ...