I've been looking around for the best way of doing this but I haven't really found anything completely convincing.
I am writing a system where you have User objects and a collection that manages those Users. Each User has a name and I want to specify a function in the manager that can either take the name of the User or the User object itself.
class UserManager:
def remove_user(self,user_or_username):
#If user_or_username is a string
remote.remove(user_or_username)
#If user_or_username is a User object
remote.remove(user_or_username.name)
Is there any nifty way of doing this or is usage of isinstance the way to go?
isinstanceshould be okay.manager.remove(username)directly.