khanna-lab / cadre

Other
0 stars 0 forks source link

Calling class method in __init__ #43

Closed khanna7 closed 2 years ago

khanna7 commented 2 years ago

https://github.com/khanna7/cadre/blob/2829019039c741f71c86dc59d25a5f86d1912ed0/python/pycadre/cadre_person.py#L29

I am calling a class method called assign_smoker_status on the Person class in its __init__ method, as shown in the line referenced in this issue.

(The class method is defined here. )

Assigning the smoker status depends on other attributes, and is a bit involved. I therefore wrote a new method to assign it. But, calling the method inside __init__, as I have done, doesn't seem to work. All smoking statuses are getting None.

Any thoughts on how to fix this?

khanna7 commented 2 years ago

Daniel says that this should work, we'll reproduce the error when Git is fixed up and troubleshoot it then.

ncollier commented 2 years ago

Assuming self.female is 0 or 1, and that that self.race is not None then yeah, self.smoker should get assigned.

khanna7 commented 2 years ago

Fixed as suggested in https://github.com/khanna7/cadre/commit/c367a8bf26c446e6c29a60a2cd505ca0d2e96537. This question at next code review.

khanna7 commented 2 years ago

Per discussion with Daniel, What I have done is right (and it works). If I want to assign self.smoker=self.assign_smoker_status(), I need to return self.smoker from the “assign_smoking_status” method.