LoginSignup
0
0

More than 3 years have passed since last update.

エラーと戦う

Last updated at Posted at 2020-11-17

pythonで出たエラーに苦戦した話

この記事は検索下手な私が「ん?これってなんのこっちゃ」ってなった体験談ww

attribute error

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

このようなエラーが出ることがある..

今回私が起こしてしまったエラーは関数の返り値がオブジェクトの際、返り値を入れるオブジェクトの内容が変わってしまった時起きた...

sample.py
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)

こんな感じで入れる変数の数が違った...

対処

sample.py
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)

ちゃんと返り値を入れようねってことだった、

自分のコードを見ればわかる話だが、エラ〜メッセージで対処しようとすると知識がないと苦戦するかも?
可読性の高いコードを書いていきたいものだ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0