2014-08-30 59 views
3
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()) 

我使用的资源文件和事情错了,当我使用它在open函数的参数,但是当我使用它的加载图片和图标一切都很好。OSERROR [错误22]无效的参数时,使用open()在Python

回答

4

这不是一个有效的文件路径。您必须使用全路径

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

或相对路径

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

你应该添加一个“/”中的最后一个“/”,例如路径: 开放(“C: \'Python34 \ book.csv')打开('C:\ Python34 \ book.csv')

import csv 
with open('C:\Python34\\book.csv', newline='') as csvfile: 
    spamreader = csv.reader(csvfile, delimiter='', quotechar='|') 
    for row in spamreader: 
     print(row) 
+1

欢迎来到Stack Overflow!虽然这可能会在理论上回答这个问题,[这将是更可取的](// meta.stackoverflow.com/q/8259)在这里包括答案的基本部分,并提供参考链接。 – manetsus 2016-01-05 16:14:49

+3

这个答案有一组问题: 1)'open('C:\ Python34 \ book.csv')'打开('C:\ Python34 \ book.csv')' - >没有区别在两条线之间。你是否打开('C:\\ Python34 \\ book.csv')'打开('C:\\ Python34 \\ book.csv')'? 2)示例中和第一行中的代码都是错误的,因为您不是逃避反斜杠(或者,在您的示例中,它们全部都是。) C:\ Python34 \\ book .csv''应该是''C:\\ Python34 \\ book.csv''或'r'C:\ Python34 \ book.csv'' – GPhilo 2017-05-31 09:41:08

相关问题