Post

PythonPython

n
naveen nani

Posted on 27th February 2024|14 views

0
votes

Python Create File If Not Exists

How do you create a file if not exist in Python?

Answers
P
naseer mohammad

Posted on 27th February 2024

Here is an example to check if the file exists and to create if there is no file

import os.path

file_exists = os.path.isfile(file_name)

 

if file_exists:

    # staments

else:

    # staments to create a file

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos