1import os
2# you have to be in the same directory as the file
3file = 'myfile.txt'
4# or also
5file = 'directory/to/myfile.txt'
6
7path = os.path.abspath(file)
8
1file = open(“testfile.txt”,”w”)
2
3file.write(“Hello World”)
4file.write(“This is our new text file”)
5file.write(“and this is another line.”)
6file.write(“Why? Because we can.”)
7
8file.close()
1>>> import os
2>>> os.path.abspath("mydir/myfile.txt")
3'C:/example/cwd/mydir/myfile.txt'
4