[IPython-dev] IPython traitlet problem

Robert McGibbon rmcgibbo@gmail....
Sat Apr 20 11:46:02 CDT 2013


Matthias,

In [1]: from IPython.utils.traitlets import HasTraits, Float

In [2]: class Foo(HasTraits):
   ...:        x = Float()
   ...:

In [3]:    def __init__(self, bar):
   ...:            pass
   ...:

In [4]: foo = Foo(bar=1)

You just need to call the constructor with a keyword argument.

-Robert

On Apr 19, 2013, at 7:24 AM, Matthias Vogelgesang wrote:

> Hi,
> 
> I am considering the traitlets module for a project of mine but there
> is one big problem: All classes that derive from HasTraits cannot have
> parameters in their __init__() method, which makes traitlets pointless
> for general purpose classes, e.g.
> 
> class Foo(HasTraits):
>    x = Float()
> 
>    def __init__(self, bar):
>        pass
> 
> gives me
> 
>  TypeError: __new__() takes exactly 1 argument (2 given)
> 
> Is this behaviour intentional?
> 
> Thanks,
> Matthias
> 
> --
> Matthias Vogelgesang
> Public-Key: http://tinyurl.com/2qcydl
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev



More information about the IPython-dev mailing list