Python pycharm中未解析的引用get_func()
很抱歉,我刚刚开始使用python,但在以下代码中有一个未解析的引用get_func()错误:Python pycharm中未解析的引用get_func(),python,function,Python,Function,很抱歉,我刚刚开始使用python,但在以下代码中有一个未解析的引用get_func()错误: class Foo: fo = open(file_name, "r") with open(file_name, 'r') as file: examples = int(file.readline()) attributes = int(file.readline()) name_of_attributes = [n
class Foo:
fo = open(file_name, "r")
with open(file_name, 'r') as file:
examples = int(file.readline())
attributes = int(file.readline())
name_of_attributes = [n for n in (file.readline().replace(" ", "")).split(",")]
all_examples = file.readlines()
get_func(); // error here
def get_func(self):
list_of_keys = ['S_Length', 'S_Width', 'P_Length', 'P_Width', 'Predicate']
with open('example.txt') as f:
for line in f:
return;
在调用函数的时候,Python还没有遇到它的定义,所以它还不知道您指的是什么。在C/C++中(从您在代码中的注释判断),编译代码和运行代码之间有着明显的区别。在Python中,解释器在概念上只是在进行时解释它(有字节码编译,但这不是重点) 尝试更改顺序,以便调用在定义之后:
def get_func(self): # first define
...
get_func() # now invoke it
要访问类方法,应使用在方法
get_func
声明中设置的self
属性,如下面的self.get_func()
。您可以在结尾处放弃冒号
我认为您应该阅读更多关于Python类的内容,请查看这篇Wikibook文章-这是本范围内的一篇未解决的引用。那里不存在名称
get_func
。我建议阅读基本的Python教程,因为这段代码显示了一些基本的错误,并且按照现在的定义回答这个问题是毫无意义的。