描述
方法readlink()返回一個字符串,表示符號鏈接指向的路徑。它可能返回絕對或相對路徑名。
用法
以下是語法readlink()方法≫
os.readlink(path)
參數
path─ 這是我們要查找鏈接源的路徑或符號鏈接。
返回值
此方法返回一個字符串,表示符號鏈接指向的路徑。
示例
下麵的例子展示了 readlink() 方法的用法。
# !/usr/bin/python3
import os
src = 'd://tmp//python3'
dst = 'd://tmp//python2'
# This creates a symbolic link on python in tmp directory
os.symlink(src, dst)
# Now let us use readlink to display the source of the link.
path = os.readlink( dst )
print (path)
結果
讓我們編譯並運行上麵的程序,這將創建一個指向 d:\tmp\python3 的符號鏈接,稍後它將使用 readlink() 調用讀取符號鏈接的源代碼。這是 Windows 平台上的示例,需要管理員權限才能運行。在運行這個程序之前,確保你沒有 d:\tmp\python2 已經可用。
d:\tmp\python2
相關用法
- Python 3 os.read()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.removedirs()用法及代碼示例
- Python 3 os.remove()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.isatty()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.readlink() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。