OSError [Errno 22] invalid argument when use open() in Python

That is not a valid file path. You must either use a full path

open(r"C:\description_files\program_description.txt","r")

Or a relative path

open("program_description.txt","r")

Add 'r' in starting of path:

path = r"D:\Folder\file.txt"

That works for me.


I also ran into this fault when I used open(file_path). My reason for this fault was that my file_path had a special character like "?" or "<".


I received the same error when trying to print an absolutely enormous dictionary. When I attempted to print just the keys of the dictionary, all was well!