继续获取名称错误名称“getName”未定义

时间:2018-04-10 20:15:03

标签: python-3.x

我一直在尝试创建一个程序来设置用户的宠物名称,种类和年龄,但最终会返回所有结果并输出结果。

如何修复此代码的名称错误?

Connection.Response Form = Jsoup
    .connect("http://www.coordinadora.com/portafolio-de-servicios/servicios-en-linea/rastrear-guias/#rastreo")
    .method(Connection.Method.GET).execute();

    Document document = Jsoup
    .connect("http://www.coordinadora.com/portafolio-de-servicios/servicios-en-linea/rastrear-guias/#rastreo")
    .data("coor_guia_home", guiaNumero.trim()).cookies(Form.cookies()).post();

1 个答案:

答案 0 :(得分:1)

要从类中访问实例变量和函数,您需要使用self

class Pet :

    def main(self) :
        print(self.getName())
        print(self.getSpecies())
        print(self.getAge())

    def getName(self) :
        name = str(input("What is your pets name: "))
        return name

    def getSpecies(self) :
        species = str(input("What is your pets species: "))
        return species

    def getAge(self) :
        age = int(input("Please type in your age: "))
        return print(age)

myPet = Pet()
myPet.main()