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
>>> 



沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) 3) 使用database需先create建立資料庫 Node-Red 程式 [...