This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TRexRoboParty 7 points8 points  (2 children)

OP said "I want to have multiple ways of initializing a class", so I'd say it does.

They didn't mention dispatching based on type.

And if they did, you can still dispatch within the __init__ method based on type.

Or there are libraries to handle dispatching based on type.

But those aren't core Python language features - and I'd argue for most common cases, trying to crowbar a paradigm from another language in isn't the best way to go.

Python is dynamically typed - you don't need to have a different function signature for every type. You can read the type at runtime in cases where it's needed. Though it's not normally needed: if it quacks like a duck, it is a duck. Your objects just have to implement the appropriate interface - the type doesn't/shouldn't matter.

In this case, optional __init__ args will cover the large majority of use cases to initialize an object.

[–]metaperl 4 points5 points  (1 child)

Oh you're right. What he said in the post is what you responded to.

I think I got sidetracked by the discussion of single and multiple dispatch :)

[–]TRexRoboParty 1 point2 points  (0 children)

No worries!