小白教程
所有教程
关于
Search
172.69.6.136
172.69.6.136
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os lseek”的源代码
本页内容
上一节:
Python3_os_listdir
下一节:
Python3_os_lstat
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.lseek(fd, pos, how)}}[[Category:python3 os file methods|29]] = Python3 os.lseek() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.lseek() 方法用于设置文件描述符 fd 当前位置为 pos, how 方式修改。 在Unix,Windows中有效。 === 语法 === '''lseek()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.lseek(fd, pos, how) </sample> === 参数 === * '''fd''' -- 文件描述符。 * '''pos''' -- 这是相对于给定的参数 how 在文件中的位置。。 * '''how''' -- 文件内参考位置。SEEK_SET 或者 0 设置从文件开始的计算的pos; SEEK_CUR或者 1 则从当前位置计算; os.SEEK_END或者2则从文件尾部开始。 === 返回值 === 该方法没有返回值。 == 以下实例演示了 lseek() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 os.write(fd, "This is test") # 所有 fsync() 方法 os.fsync(fd) # 从开始位置读取字符串 os.lseek(fd, 0, 0) str = os.read(fd, 100) print ("Read String is : ", str) # 关闭文件 os.close( fd ) print ("关闭文件成功!!") </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 关闭文件成功!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os lseek
”。
上一节:
Python3_os_listdir
下一节:
Python3_os_lstat