2018年1月8日 星期一

Python: Check whether a file exists using Python

Python: Check whether a file exists using Python

Python Basic: Exercise-41 with Solution

Write a Python program to check whether a file exists.
Sample Solution:-
import os.path
open('abc.txt', 'w')
print(os.path.isfile('abc.txt'))
if os.path.isfile("C:\test.txt"):
    print ("Is File")
else:
    print ("Is Not File")
if os.path.isfile(r"\\full\uncpath\test.txt"):
    print ("Is File")
else:

    print ("Is Not File")
============ RESTART: F:/Python_APSC/py-ex-basic-41.py ============
True
Is Not File
Is Not File
>>> 



沒有留言:

張貼留言

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

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