You'd want to raise an error within the __init__
method:
if not isinstance(name,basestring):
raise TypeError("I don't think that is a name ...")
*Note that basestring
also includes unicode
for python2.x, but isn't available in python3.x.
Careful though, there is nothing here to prevent a user from re-setting the person's name to a list after the person
has been constructed.
jack = Person("Jack")
jack.name = ["cheese","steak"] #???
If you want to have this safety built in, you'll need to start learning about property
.