fork download
  1. class Image:
  2. def __init__(self, path: str):
  3. self.path: str = path
  4.  
  5.  
  6. class Window:
  7. image: Image # instance variable without default
  8.  
  9. def __init__(self):
  10. self.fish: str = "123"
  11.  
  12. def build(self, path):
  13. self.image = Image(path)
  14.  
  15.  
  16. window1 = Window()
  17. window1.build('path1')
  18.  
  19. window2 = Window()
  20. window2.build('path2')
  21.  
  22. print(window1.image.path)
  23. print(window2.image.path)
  24. print(window1.image.path)
  25.  
  26. # Only downside I can see: two errors when attempt to use as a class variable
  27. # print(Window.image) # not flagged by PyCharm
  28. # print(Window.fish) # flagged by PyCharm
  29. # Not a big problem for me since I don't often use Class Variables and maybe ClassVar will be supported in future
  30.  
Success #stdin #stdout 0.02s 9256KB
stdin
Standard input is empty
stdout
path1
path2
path1