Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Advanced Objects Constructicons

tomtrnka
tomtrnka
9,780 Points

classmethods name convention

Hi, I heard somewhere else, that when we want to define a class method and use it as a alternative constructor, the naming convention is that the method name should start with "from_ ..". Whats the truth behind this? Or am I mixing it up with something else?

1 Answer

Steven Parker
Steven Parker
231,248 Points

I don't think it quite qualifies as a universal "best practice", but it is common to name class methods that return a new instance using a specific source reference as "from_source".

There are examples of this in the courses, one in particular that comes to mind is a morse code class that generates a new instance from a string when you call "from_string".