def choose_option(self): if self.option_picker.currentRow() == 0: description = open(":/description_files/program_description.txt","r") self.information_shower.setText(description.read()) elif self.option_picker.currentRow() == 1: requirements = open(":/description_files/requirements_for_client_data.txt", "r") self.information_shower.setText(requirements.read()) elif self.option_picker.currentRow() == 2: menus = open(":/description_files/menus.txt", "r") self.information_shower.setText(menus.read())I am using resource files and something is going wrong when i am using it as argument in open function, but when i am using it for loading of pictures and icons everything is fine.
215 Answers
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") 2 Add 'r' in starting of path:
path = r"D:\Folder\file.txt"That works for me.
2I 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!
In my case, I was using an invalid string prefix.
Wrong:
path = f"D:\Folder\file.txt"Right:
path = r"D:\Folder\file.txt" In my case the error was due to lack of permissions to the folder path. I entered and saved the credentials and the issue was solved.
you should add one more "/" in the last "/" of path, that is:open('C:\Python34\book.csv') to open('C:\Python34\\book.csv'). For example:
import csv
with open('C:\Python34\\book.csv', newline='') as csvfile: spamreader = csv.reader(csvfile, delimiter='', quotechar='|') for row in spamreader: print(row) 3 Just replace with "/" for file path :
open("description_files/program_description.txt","r") 1 In Windows-Pycharm: If File Location|Path contains any string like \t then need to escape that with additional \ like \\t
I had the same problem It happens because files can't contain special characters like ":", "?", ">" and etc. You should replace these files by using replace() function:
filename = filename.replace("special character to replace", "-") just use single quotation marks only and use 'r' raw string upfront and a single '/'
for eg
f = open(r'C:/Desktop/file.txt','r')
print(f.read()) for folder, subs, files in os.walk(unicode(docs_dir, 'utf-8')): for filename in files: if not filename.startswith('.'): file_path = os.path.join(folder, filename) In my case,the problem exists beacause I have not set permission for drive "C:\" and when I change my path to other drive like "F:\" my problem resolved.
import pandas as pd
df = pd.read_excel ('C:/Users/yourlogin/new folder/file.xlsx')
print (df) 2 I got this error because old server instance was running and using log file, hence new instance was not able to write to log file. Post deleting log file this issue got resolved.