Something like this?

>>> class Test(object):
...     def __init__(self, arg):
...         if not isinstance(arg, int):
...             raise TypeError('arg {0} must be an integer.'.format(arg))
...         self.arg = arg
...
>>> Test(1)
<__main__.Test object at 0x02F72490>
>>> Test('a')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "<input>", line 4, in __init__
TypeError: arg a must be an integer.

On Wed, Apr 28, 2010 at 6:18 AM, shawnpatapoff <[email protected]>wrote:

> This may be a more basic question.
>
> I have a class being created and I'm testing the arguments when the
> class is called. Within the class can I error out if the types are
> wrong and prevent the class from returning? How do you guys handle
> this?
>
> Cheers,
> Shawn
>
> --
> http://groups.google.com/group/python_inside_maya

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to