Skip to main content

All Questions

Tagged with
3 votes
1 answer
391 views

Does adding values to a dictionary in the constructor violate that "a constructor shouldn't do work"?

Some what of a followup to this question. Suppose I have a Player class with a dictionary call attributes that holds the Health and Mana of the player. In this example, I'll use Python, but my ...
user avatar
1 vote
1 answer
352 views

Does creating a list in the constructor violate the guideline that a constructor shouldn't do work?

I was reading these pages (1,2,3), but I'm still unsure if this violates the guideline. I have the following data being read from a website: Date: July 13, 2018 Type: Partial Solar Eclipse Location:...
user avatar
0 votes
1 answer
847 views

Should I put the parameters in constructor or in method? (Python 3)

I have the following code: def __init__(self, vocable_file_path, xsd_file_path, word_list_file_path): self.vocable_file_path = vocable_file_path self.xsd_file_path = xsd_file_path self....
Zelphir Kaltstahl's user avatar
-1 votes
1 answer
197 views

Conversion methods: from_xxx() or to_xxx(), is there a reason I shouldn't stick with to_xxx()?

I have a C++ library that I'm converting to Python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of ...
Krupip's user avatar
  • 1,320
-3 votes
1 answer
2k views

Why constructor inheritance is not supported in Python? [closed]

Consider the case where I have the following classes, class A: def __init__(self): print("Class A") class B(A): def __init__(self): print("Class B") b = B() The expected ...
Saurabh P Bhandari's user avatar