Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

pyhton if exists code example

Example 1: python check if file exists

import os

os.path.exists("file.txt") # Or folder, will return true or false

Example 2: python check if file exists

#using pathlib
from pathlib import Path

file_name = Path("file.txt")
if file_name.exists():
    print("exists") 
else:
    print("does not exist")

Tags:

Python Example

Related

WSL 2 on windows code example react set props code example sql not equal string with or code example how to make long text not go code example key code list code example how to center a image in a container code example button tag template code example syntax for for of loop javascript code example how to use group function in mongodb code example function split in python code example install jupyter notebook on pychram code example find mac address using ip code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy