小白教程
所有教程
关于
Search
172.69.58.43
172.69.58.43
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Python3 os link”的源代码
本页内容
上一节:
Python3_os_lchown
下一节:
Python3_os_listdir
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:os.link(src, dst)}}[[Category:python3 os file methods|27]] = Python3 os.link() 方法 = [[python3 os file methods|Python3 OS 文件/目录方法]] === 概述 === os.link() 方法用于创建硬链接,名为参数 dst,指向参数 src。 该方法对于创建一个已存在文件的拷贝是非常有用的。 只支持在 Unix, Windows 下使用。 === 语法 === '''link()'''方法语法格式如下: <sample title="" desc="" lang="python" hererun="1"> os.link(src, dst) </sample> === 参数 === * '''src''' -- 用于创建硬连接的源地址 * '''dst''' -- 用于创建硬连接的目标地址 === 返回值 === 该方法没有返回值。 == 以下实例演示了 link() 方法的使用: <sample title="" desc="" lang="python" hererun="1"> #!/usr/bin/python3 import os, sys # 打开文件 path = "/var/www/html/foo.txt" fd = os.open( path, os.O_RDWR|os.O_CREAT ) # 关闭文件 os.close( fd ) # 创建以上文件的拷贝 dst = "/tmp/foo.txt" os.link( path, dst) print ("创建硬链接成功!!") </sample> 执行以上程序输出结果为: <sample title="" desc="" lang="python" hererun="1"> 创建硬链接成功!! </sample> [[python3 os file methods|Python3 OS 文件/目录方法]]
返回至“
Python3 os link
”。
上一节:
Python3_os_lchown
下一节:
Python3_os_listdir