I've been working on a python application that takes input from the user.
The input is the path to a text file.
Once the user has entered the path to a text file, it will be opened, and the contents displayed in the console.
file = input()
with open(file, "r") as file:
content = file.read()
Currently, it will only accept 'literal file paths', for example C:/users/name/documents/filename.txt
I would like it to accept relative file paths aswell, for example ./file.txt
, which should get a file named file.txt
in the current directory, or ../file2.txt
which should go up a directory (..
) and then get a file called file2.txt
.
How can I achieve this?
I was unable to find any relevant answers.