• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Python strange namespace bahavior for class factory

Resolved: Python strange namespace bahavior for class factory

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I tried to write simple class factory using the “type” method. I called myclass_factory twice and It returned identical namespaces (case1 and case2). But the values of myclass attribute in that namespaces were different (!). Actualy it just what I need but I can not undestnad why I got that result. For my udestanding, since case1 and case2 are not objects but just same namespace (<class ‘main.MyClass’>) they should refer to the same memory and should be case1.myclass = case2.myclass
Please explain how It could be so?

Answer:

Actually case 1 and case 2 are objects since you instantiate them. They are type objects and thus ordinary python objects. So you create two different type objects.
also see this answer: Link to answer
Also see This description

If you have better answer, please add a comment about this, thank you!

factory namespaces python types
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: navigate and redirect not redirecting to path in react router

24/03/2023

Resolved: Time Complexity: Find the number of people who know a secret leetcode 2327

24/03/2023

Resolved: Best way to create 3d matrix of variables in PULP

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.