0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

pythonでclass名を上書きする方法

Last updated at Posted at 2022-04-07
1 / 2

どうしようもなくてこんなことをしたくなったんだけど

syntax errorかと思いきや、イケるのね・・・でも結果は、、

class AAA:
    status = "Former one"

class User(AAA):
    aaa = AAA()                # 上書きされた後にcallされる

    def do(self):
        print(self.aaa.status)

class AAA(AAA):              # 上書き
    status = "Latter one"

if __name__ == "__main__":
    # debug
    user = User()
    user.do()

result

$ python aaa.py
Former one

だめぽい!

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?