[Nipy-devel] help with attributes
Brian Hawthorne
brian.lee.hawthorne at gmail.com
Fri May 19 02:27:05 CDT 2006
>
> > from attributes import readonly
> > class Test (object):
> > class x (readonly): default=4.
> >
> > d = Test()
> > d.x = 3.
> > d.y = 4.
> >
>
> Yes, but it won't fail with
>
> d.x = 'a'
>
> which is the commented out example in my script, i.e. there is no type
> checking, which I think is another nice feature of traits.
Attributes do perform (duck-)type checking. It will fail on d.x='a', because
if a default value is specified, but no type is specified, an attribute
takes the type of its default (in this case a float, which is why I put a
period after the 4). I do encourage everyone to take a look at the
mini-tutorial doctest:
http://neuroimaging.scipy.org/api/attributes-module.html
- Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/nipy-devel/attachments/20060519/c491551a/attachment-0002.html
More information about the Nipy-devel
mailing list