【发布时间】:2016-04-17 13:49:24
【问题描述】:
我对 Python 很陌生,很抱歉,如果我很讨厌,但是每当我尝试我的代码时,我都会收到这个错误,错误如下:
Traceback (most recent call last):<br>
File "<pyshell#3>", line 1, in <module>
fopen.open_file()
TypeError:<br> unbound method open_file() must be called with openFile instance as first argument (got nothing instead)
程序的目的是读入用户输入的文件。
这是我的代码:
class openFile:
def file_to_open():
fopen = raw_input('Enter the file path : ')
open_file = open(fopen)
print open_file
【问题讨论】:
-
你为什么要使用类?
-
引发的异常与您的代码不对应。
-
你是如何使用那个类来创建你的实例的?
标签: python function python-2.7 class methods