I'm trying to make a python script (PyCharm, python version 3.9) which you can write and read any document on my laptop, however, the backslashes in the path of the text file are being read incorrectly when i use it as:
global file def start(): global file print("text file:") file = input() print("type:") m = input() if m == 'r': read() def read(): with open(file, 'a+') as f: f.seek(0) print(f.read()) the console when i run it is:
script >> text file: me >> "C:\Users\mylan\Downloads\test.txt" script >> type: me >> r

The error I'm facing is:
OSError: [Errno 22] Invalid argument: '"C:\\Users\\mylan\\Downloads\\test.txt"' I have already searched for related questions and answers but could only find a solution using a r in front:
file = r"C:\Users\mylan\Downloads\test.txt The problem with this, however, is that the file that is read is set in code instead of coming from the input, so, is it possible to get the effect of using r"C:..." while using input() ?
Источник: https://stackoverflow.com/questions/780 ... -text-file