2018年1月10日 星期三

Python: Find path refers to a file or directory when you encounter a path name

Python: Find path refers to a file or directory when you encounter a path name 找到到路徑名稱時,查找路徑指的是檔案或目錄

Python Basic: Exercise-108 with Solution

Write a Python program to find path refers to a file or directory when you encounter a path name.
Sample Solution:-
import os.path

for file in [ __file__, os.path.dirname(__file__), '/', './broken_link']:
    print('File        :', file)
    print('Absolute    :', os.path.isabs(file))
    print('Is File?    :', os.path.isfile(file))
    print('Is Dir?     :', os.path.isdir(file))
    print('Is Link?    :', os.path.islink(file))
    print('Exists?     :', os.path.exists(file))
    print('Link Exists?:', os.path.lexists(file))


================= RESTART: F:/Python_APSC/py-ex-basic-108.py =================
File        : F:/Python_APSC/py-ex-basic-108.py
Absolute    : True
Is File?    : True
Is Dir?     : False
Is Link?    : False
Exists?     : True
Link Exists?: True
File        : F:/Python_APSC
Absolute    : True
Is File?    : False
Is Dir?     : True
Is Link?    : False
Exists?     : True
Link Exists?: True
File        : /
Absolute    : True
Is File?    : False
Is Dir?     : True
Is Link?    : False
Exists?     : True
Link Exists?: True
File        : ./broken_link
Absolute    : False
Is File?    : False
Is Dir?     : False
Is Link?    : False
Exists?     : False
Link Exists?: False
>>> 

沒有留言:

張貼留言

Node-Red --> MQTT --> Fuxa 開源碼網頁式圖控平台

Node-Red --> MQTT --> Fuxa      FUXA(一個開源的 Web HMI / SCADA 自動化監控軟體)的專案設定檔 。 這份設定檔完整定義了 HMI 監控畫面的 後端通訊(MQTT 連線、點位標籤) 與 前端網頁圖形介面(SVG 畫布...