[PYTHON] Fight errors

A story that struggled with an error in python

This article is an experience story that I, who is not good at searching, said "What is this?"

attribute error

AttributeError: module(object) ‘xxx’ has no attribute ‘yyy’

You may get an error like this ..

The error I made this time was when the return value of the function was an object and the content of the object to put the return value changed ...

class Person:
    def __init__(self, name:str, age:int):
        self.name = name
        self.age = age

def renamed(person, pserson2):
    person.name = 'Kein'
    return person, ron

bob = Person('Bob', 19)
ron = Person('Ron', 23)
kein = renamed(bob, ron)
print(kein.name)
print(kein.age)
print(ron.name)
print(ron.age)

The number of variables to put in like this was different ...

Coping

class Person:
    def __init__(self, name:str, age:int):
        self.name = name
        self.age = age

def renamed(person, pserson2):
    person.name = 'Kein'
    return person, ron

bob = Person('Bob', 19)
ron = Person('Ron', 23)
kein, ron = renamed(bob, ron)
print(kein.name)
print(kein.age)
print(ron.name)
print(ron.age)

I was trying to put in the return price properly,

As you can see from your own code, if you try to deal with it with an error message, you may struggle without knowledge. I want to write highly readable code

Recommended Posts

Fight errors