Thoughts on using isinstance
codecraig at gmail.com
Wed Jan 24 13:38:30 CET 2007
In my code I am debating whether or not to validate the types of data
being passed to my functions. For example
def sayHello(self, name):
if not name:
rasie "name can't be null"
if not isinstance(name, str):
raise "name must be a string"
print "Hello " + name
Is the use of isinstance a "bad" way of doing things? is it a "heavy"
operation? for example, if I use this in each function validate input
will it slow things down a lot?
just curious how you might handle this type of situation (other than
not validating at all).
More information about the Python-list