python开发_stat
当我们使用os.stat(path)获取一个文件(夹)信息的时候,
os.stat(path)本身返回的是一个元组如:
nt.stat_result(st_mode=33206, st_ino=203224933185146561, st_dev=0,
st_nlink=1, st_uid=0, st_gid=0, st_size=21090, st_atime=1376373336,
st_mtime=1376534141, st_ctime=1376373336)
在这个元组中,包含了10个属性:
st_mode -- protection bits(模式)
st_ino -- inode number(索引号)
st_dev -- device(设备)
st_nlink -- number of hard links(硬链接号)
st_uid -- user id of owner(用户id)
st_gid -- group id of owner (组id)
st_size -- size of file,in bytes (大小)
st_atime -- time of most recent access expressed in seconds (访问时间)
st_mtime -- time of most recent content modificatin expressed in seconds (修改时间)
st_ctime -- platform dependent;time of most recent metadata change on Unix,
or the teime of creation on Windows,expressed in senconds (根据不同操作系统而定)
#############################################################
而stat在这里起到什么作用呢?
类似于java中定义的一些常量:
如:
os.stat(path).st_size
os.stat(path)[stat.ST_SIZE]
这两种表示方法是一样的。
下面是我做的demo:
运行效果:

==============================================
代码部分:
==============================================
#python stat
'''
当我们使用os.stat(path)获取一个文件(夹)信息的时候,
os.stat(path)本身返回的是一个元组如: nt.stat_result(st_mode=33206, st_ino=203224933185146561, st_dev=0,
st_nlink=1, st_uid=0, st_gid=0, st_size=21090, st_atime=1376373336,
st_mtime=1376534141, st_ctime=1376373336) 在这个元组中,包含了10个属性:
st_mode -- protection bits(模式)
st_ino -- inode number(索引号)
st_dev -- device(设备)
st_nlink -- number of hard links(硬链接号)
st_uid -- user id of owner(用户id)
st_gid -- group id of owner (组id)
st_size -- size of file,in bytes (大小)
st_atime -- time of most recent access expressed in seconds (访问时间)
st_mtime -- time of most recent content modificatin expressed in seconds (修改时间)
st_ctime -- platform dependent;time of most recent metadata change on Unix,
or the teime of creation on Windows,expressed in senconds (根据不同操作系统而定) #############################################################
而stat在这里起到什么作用呢?
类似于java中定义的一些常量:
如:
os.stat(path).st_size
os.stat(path)[stat.ST_SIZE]
这两种表示方法是一样的。
'''
import os
import time
import stat def get_file_stat(path):
'''获取一个文件(夹)信息,该信息将以一个元组的形式返回'''
if os.path.exists(path):
return os.stat(path)
else:
print('the path [{}] is not exist!'.format(path)) def print_info(file_stat):
'''打印信息'''
if file_stat != None:
file_info = {
'Size' : file_stat [ stat.ST_SIZE ], #获取文件大小
'LastModified' : time.ctime( file_stat [ stat.ST_MTIME ] ), #获取文件最后修改时间
'LastAccessed' : time.ctime( file_stat [ stat.ST_ATIME ] ), #获取文件最后访问时间
'CreationTime' : time.ctime( file_stat [ stat.ST_CTIME ] ), #获取文件创建时间
'Mode' : file_stat [ stat.ST_MODE ], #获取文件的模式
'Device' : file_stat [stat.ST_DEV], #设备
'UserID' : file_stat [stat.ST_UID],
'GroupID' : file_stat [stat.ST_GID]
}
for key in file_info:
print('{} : {}'.format(key, file_info[key]))
else:
print('the stat is None!') def main():
path_dir = 'c:\\Download'
path_file = 'c:\\test.html'
print('目录信息:')
file_stat = get_file_stat(path_dir)
print_info(file_stat)
print('#' * 50)
print('文件信息:')
file_stat = get_file_stat(path_file)
print_info(file_stat) if __name__ == '__main__':
main()
python开发_stat的更多相关文章
- python开发环境搭建
虽然网上有很多python开发环境搭建的文章,不过重复造轮子还是要的,记录一下过程,方便自己以后配置,也方便正在学习中的同事配置他们的环境. 1.准备好安装包 1)上python官网下载python运 ...
- 【Machine Learning】Python开发工具:Anaconda+Sublime
Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...
- Python开发工具PyCharm个性化设置(图解)
Python开发工具PyCharm个性化设置,包括设置默认PyCharm解析器.设置缩进符为制表符.设置IDE皮肤主题等,大家参考使用吧. JetBrains PyCharm Pro 4.5.3 中文 ...
- Python黑帽编程1.2 基于VS Code构建Python开发环境
Python黑帽编程1.2 基于VS Code构建Python开发环境 0.1 本系列教程说明 本系列教程,采用的大纲母本为<Understanding Network Hacks Atta ...
- Eclipse中Python开发环境搭建
Eclipse中Python开发环境搭建 目 录 1.背景介绍 2.Python安装 3.插件PyDev安装 4.测试Demo演示 一.背景介绍 Eclipse是一款基于Java的可扩展开发平台. ...
- Python开发:环境搭建(python3、PyCharm)
Python开发:环境搭建(python3.PyCharm) python3版本安装 PyCharm使用(完全图解(最新经典))
- Python 开发轻量级爬虫08
Python 开发轻量级爬虫 (imooc总结08--爬虫实例--分析目标) 怎么开发一个爬虫?开发一个爬虫包含哪些步骤呢? 1.确定要抓取得目标,即抓取哪些网站的哪些网页的哪部分数据. 本实例确定抓 ...
- Python 开发轻量级爬虫07
Python 开发轻量级爬虫 (imooc总结07--网页解析器BeautifulSoup) BeautifulSoup下载和安装 使用pip install 安装:在命令行cmd之后输入,pip i ...
- Python 开发轻量级爬虫06
Python 开发轻量级爬虫 (imooc总结06--网页解析器) 介绍网页解析器 将互联网的网页获取到本地以后,我们需要对它们进行解析才能够提取出我们需要的内容. 也就是说网页解析器是从网页中提取有 ...
随机推荐
- springJDBC 中JdbcTemplate 类方法使用
一,Dao IUserinfDao package com.dkt.dao; import java.util.List; import com.dkt.entity.Userinfo; public ...
- BZOJ4466 [Jsoi2013]超立方体
Description 定义"超立方图"为:有\(2^k\)个点,以\(k\)位二进制数编号,两个点之间有边当且仅当它们的编号恰有一位不同.给出一个图,问它是否与"超立方 ...
- Task15 节点层次笔记
childElementCount : 返回子元素的个数 (不包括文本节点和注释节点) children:返回指定元素的子元素集合,它只返回HTML节点,甚至不返回文本节点,虽然不是标准的DOM属性, ...
- IOS下 input 被软键盘方案遮盖问题解决
前言: 并没有完美解决 ! 场景: 最近在做企业微信H5的一个项目,里面有个动态列表页,开始输入框是隐藏的,点击评论才会出现并让 input 聚焦.经过测试在安卓上面应该没什么问题,但是iOS上面会出 ...
- mac系统使用介绍
点击左上角苹果-->关于本机 Dock-->偏好设置 推荐按装mac系统:OS X V10.8(山狮) Finder-->应用程序(安装程序)<==>我的电脑 Safar ...
- Memory map of an object array
Student类: package com.itheima; /* * 自动生成构造方法: * 代码区域右键 -- Source -- Generate Constructors from Super ...
- text-overflow修剪文本,以省略号显示
overflow: hidden; 必须设置,不然无法修剪文本 white-space: nowrap; 规定段落中的文本不进行换行 text-overflow: ellipsis; 当文本溢出 ...
- apache ftp server的简单入门(java应用内嵌ftp server)
Apache Ftp Server:(强调) Apache Ftp Server 是100%纯Java的FTP服务器软件,它采用MINA网络框架开发具有非常好的性能.Apache FtpServer ...
- python学习手册中的一些易忘的点(前三部分)
1.ubuntu下让python脚本可直接运行: test.py文件(后缀可省)#!/usr/bin/pythonprint('wwwww') sudo chmod +x ./test.py (sud ...
- pytts3语音合成遇到的中文问题
在使用pytts3语音合成时,遇到中文语音错乱.程序代码本身很简单,也是网上公认的一种写法: #coding: UTF-8import pyttsx3; engine = pyttsx3.init() ...