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/ ...
随机推荐
- Attention-over-Attention Neural Networks for Reading Comprehension论文总结
Attention-over-Attention Neural Networks for Reading Comprehension 论文地址:https://arxiv.org/pdf/1607.0 ...
- CentOS测网速
当发现上网速度变慢时,人们通常会先首先测试自己的电脑到网络服务提供商(通常被称为"最后一公里")的网络连接速度.在可用于测试宽带速度的网站中,Speedtest.net也许是使用最 ...
- Ubuntu 14.04 64位上安装wps office软件(转http://m.blog.csdn.net/blog/yhc13429826359/24179933)
废话少说,只给出方法供各位参考!wps for Linux版本已经有两三年没有大的动作,当然其他平台,比如windows,Android,ios上的wps效果还是很赞的说. 下面是我成功安装的步骤: ...
- Linux下多路径multipath配置【转】
一.multipath在redhat 6.2中的基本配置: 1. 通过命令:lsmod |grep dm_multipath 检查是否正常安装成功.如果没有输出说明没有安装那么通过yum功能安装一下 ...
- ACM International Collegiate Programming Contest World Finals 2013
ACM International Collegiate Programming Contest World Finals 2013 A - Self-Assembly 题目描述:给出\(n\)个正方 ...
- ps的各种参数
1.CPU占用最多的前10个进程: ps auxw|head -1;ps auxw|sort -rn -k3|head -10 2.内存消耗最多的前10个进程 ps auxw|head -1;ps a ...
- Windows内核读书笔记——SEH结构化异常处理
SEH是对windows系统中的异常分发和处理机制的总称,其实现分布在很多不同的模块中. SEH提供了终结处理和异常处理两种功能. 终结处理保证终结处理块中的程序一定会被执行 __try { //要保 ...
- es6的set和get实现数据双向绑定,监听变量变化。
直接上代码吧,这个用法真的是效仿了.net的枚举. vue的数据双向绑定就是用这个实现的. 代码: html: <input type="text" id="inp ...
- c# 递归异步获取本地驱动器下所有文件
//获取所有驱动器 string[] drives = Environment.GetLogicalDrives(); foreach (string driver in drives) { Cons ...
- linux网络管理----网络基础
1.1 ISO/OSI 七层模型 笔记: 打入ipconfig: mac地址:Media Access Control 也是物理地址,这是由网卡决定的.负责的是内网,也就是局域网通信. IPv4地址: ...