"File not Found" Error while using "With Open" and absolute path with Python

16 Views Asked by At

I am developing a simple webservice with Python/Flask.

I have this code that should write to a config file located one step down from my root directory where I am running the program:

config_file_path = abspath("text_files\config.txt")
    with open(config_file_path, 'w') as txt:
        txt.write(f"{report_input}: {record_input}")

But I get an error that says:

  File "C:\Users\Tech4\Desktop\python_server_test\server.py", line 26, in form_post
    with open(config_file_path, 'w') as txt:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Tech4\\text_files\\config.txt'

Why does this happen?

0

There are 0 best solutions below