30
loading...
This website collects cookies to deliver better user experience
open()
function. There are other methods that utilize the OS module in Python, however, a few methods would require root permission. Hence to standardize this tutorial I have only used the open()
method. open(file, access mode)
open()
methods require two parameters, File
- Required, the name or path of the file. Access mode
- Access modes govern the type of operations you would be performing. f = open("myfirstfile.txt", "x")
open()
to create a file, since we have not specified a path, the file is created in the same directory as the script. FileExistsError
. Try running the same code twice and you will receive this error. FileNotFoundError
is returned. FileNotFoundError
is returned if the file does not exist.