how to create a file in a specific location in python

file = open(r'C:\', 'a')  # C:\ is the location

Here is what the above code is Doing:
1. The open() function is used to open files in our system, the filename is the name of the file to be opened or created, the mode is optional which tells the interpreter and developer which way the file is going to be used, e.g. read only (‘r’), write only (‘w’), read and write (‘r+’), append only (‘a’), exclusive creation (‘x’).
2. The open() function returns a file object, also called a handle, as it is used to read or modify the file accordingly.
3. In our example, we open the file in append mode, if the file does not exist, it creates one.
4. The write() method is then used to write text to the file.
5. The close() method is used to close the file.