Important Notice:

Create Mode — x

Create Mode — x

3 views 1 min read

Create Mode — x :-

Create Mode का उपयोग केवल नई file create करने के लिए किया जाता है। यदि उसी नाम की file पहले से मौजूद है, तो Python FileExistsError देता है।

English:

Create mode is used to create a new file exclusively. If a file with the same name already exists, Python raises a FileExistsError.

Syntax -

file = open("filename.txt", "x")


Example

file = open("newfile.txt", "x")

file.write("This is a new file")

file.close()

print("File Created Successfully")

Output:

File Created Successfully

Important Points

  1. x का अर्थ Exclusive Creation Mode है।

  2. यह नई file create करता है।

  3. Existing file को overwrite नहीं करता।

  4. File पहले से मौजूद होने पर FileExistsError देता है।

  5. यह अनजाने में existing data overwrite होने से बचाता है।

Related Notes