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/ ...
随机推荐
- Linux下libevent安装与示例
http://www.cnblogs.com/kunhu/p/3632225.html
- adb_usb.ini在adb找不到设备时
不能连接不上adb,如下方法解决,步骤描述不愿意看的话,直接使用本文最下面的批处理命令,方法copy粘贴到新建的bat文件里运行,或者直接粘贴到dos窗口运行. 1. 使用androidsdk目录中的 ...
- sea.js中的checkbox批量操作
<table width="100%" border="0" cellspacing="0" cellpadding="0& ...
- Repository.UpdateModel(model, db);
Repository.UpdateModel(model, db); 可用类型 string int? datetime 不可用类型 int double
- 「caffe编译bug」 undefined reference to `boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::__cxx11
CXX/LD -o .build_release/tools/test_net.binCXX/LD -o .build_release/tools/convert_annoset.binCXX/LD ...
- nginx 各种配置
first : mkdir /usr/local/nginx/conf/vhosts{网站配置}/usr/local/nginx/conf/vhosts/test.conf : server { li ...
- JavaScript变量命名规则:匈牙利命名法
匈牙利命名法语法 变量名=类型+对象描述 类型指变量的类型 对象描述指对象名字全称或名字的一部分,要求有明确含义,命名要容易记忆容易理解. 提示 虽然JavaScript变量表面上没有类型,但是Jav ...
- free之后将指针置为NULL
free一个指针,只是将指针指向的内存空间释放掉了,并没有将指针置为NULL,指针仍指向被释放掉的内存的地址,在判断指针是否为NULL的时候,通常是通过if(pt == NULL) ,这时,导致指针成 ...
- xcode没有ios7的模拟器
xcode7 目前只支持 ios8盒和iOS9的模拟器如果是Yosemite系统,下载xcode7和xcode6.4,两个版本可以共存,然后再下载iOS7默契你如果是EI Caption系统,网上说E ...
- yii2联表查询
我们用实例来说明这一部分 表结构 现在有客户表.订单表.图书表.作者表, 客户表Customer (id customer_name) 订单表Order (id order_ ...