首页 > Python资料 博客日记
Python os.lstat()方法
2023-08-08 14:59:45Python资料围观193次
本篇文章分享Python os.lstat()方法,对你有帮助的话记得收藏一下,看Python资料网收获更多编程知识
Python的lseek()
方法与fstat()
非常相似,并返回一个包含有关文件信息的stat_result
对象,但不要跟随符号链接。这是在不支持符号链接的平台上的fstat()
的别名,例如:Windows。
这是lstat
方法返回的结构 -
st_dev
- 包含文件的设备的IDst_ino
- inode编号st_mode
- 保护st_nlink
- 硬链接数st_uid
- 所有者的用户IDst_gid
- 所有者的组IDst_rdev
- 设备ID(如果是特殊文件)st_size
- 总大小(以字节为单位)st_blksize
- 文件系统I/O的块大小st_blocks
- 分配的块数st_atime
- 上次访问的时间st_mtime
- 上次修改的时间st_ctime
- 上次状态更改的时间
语法
以下是lstat()
方法的语法 -
os.lstat(path)
参数
- path - 这是文件描述符,需要处理。
定义的pos
常数 -
os.SEEK_SET = 0
os.SEEK_CUR = 1
os.SEEK_END = 2
返回值
- 这是要返回信息的文件。
示例
以下示例显示了lstat()
方法的用法。
#!/usr/bin/python3
import os, sys
# Open a file
path = "d:\\python3\\foo.txt"
fd = os.open( path, os.O_RDWR|os.O_CREAT )
# Close opened file
os.close( fd )
# Now get the touple
info = os.lstat(path)
print ("File Info :", info)
# Now get uid of the file
print ("UID of the file :%d" % info.st_uid)
# Now get gid of the file
print ("GID of the file :%d" % info.st_gid)
执行上面代码后,将得到以下结果 -
File Info : os.stat_result(st_mode=33206, st_ino=281474976797706, st_dev=1017554828, st_nlink=2, st_uid=0, st_gid=0, st_size=13, st_atime=1455597777, st_mtime=1438077266, st_ctime=1455560006)
UID of the file :0
GID of the file :0
版权声明:本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:jacktools123@163.com进行投诉反馈,一经查实,立即删除!
标签:
相关文章
最新发布
- Python pycryptodome类库使用学习总结
- import torch 报错:WinError 126
- 如何在Java中实现邮件发送功能?
- python之openpyxl模块——实现Excel表格的处理(万字教学,全网最全,超详细!)
- BUG解决:postman可以请求成功,但Python requests请求报403
- 解决Pycharm下载torch报错:OSError: [WinError 126] 找不到指定的模块。
- python创建线程和结束线程
- 精通Python(基础篇)pip命令大全(非常详细)零基础入门到精通,收藏这一篇就够了
- Python中的列表(list)
- ImportError: /usr/local/lib/python3.8/dist-packages/flash_attn_2_cuda.cpython-38-x86_64-linux-gnu.so
点击排行
- 版本匹配指南:Numpy版本和Python版本的对应关系
- Python 可视化 web 神器:streamlit、Gradio、dash、nicegui;低代码 Python Web 框架:PyWebIO
- 版本匹配指南:PyTorch版本、torchvision 版本和Python版本的对应关系
- 相关性分析——Pearson相关系数+热力图(附data和Python完整代码)
- Could not build wheels for llama-cpp-python, which is required to install pyproject.toml-based proj
- Python pyinstaller打包exe最完整教程
- Anaconda版本和Python版本对应关系(持续更新...)
- Python与PyTorch的版本对应