Re: __init__ style questions

2006-10-02 Thread bearophileHUGS
Will McGugan: > I am writting a Vector3D class as a teaching aid (not for me, for > others), and I find myself pondering over the __init__ function. I want > it to be as easy to use as possible (speed is a secondary > consideration). If optimizations are less important, then don't use __slots__, i

Re: __init__ style questions

2006-10-02 Thread Gerard Flanagan
Will McGugan wrote: > I am writting a Vector3D class as a teaching aid (not for me, for > others), and I find myself pondering over the __init__ function. I want > it to be as easy to use as possible (speed is a secondary > consideration). > > Heres the __init__ function I have at the moment. > >

Re: __init__ style questions

2006-10-02 Thread Will McGugan
Duncan Booth wrote: > > Yes, it would, although since the implication is that your class expected > numbers and the file iterator returns strings I'm not sure how much it > matters: you are still going to have to write more code than in your > example above. e.g. > >v1 = Vector3D(float(n) for

Re: __init__ style questions

2006-10-02 Thread Duncan Booth
"Will McGugan" <[EMAIL PROTECTED]> wrote: > Duncan Booth wrote: > >> No it isn't Pythonic. Why not just require 3 values and move the >> responsibility onto the caller to pass them correctly? They can still >> use an iterator if they want: >> >> Vector3D(a, b, c) >> Vector3D(*some_iter) >

Re: __init__ style questions

2006-10-02 Thread Duncan Booth
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote: > Duncan Booth wrote: > >> No it isn't Pythonic. > > rubbish. using a single constructor that handles two common use cases is > perfectly Pythonic (especially if you're targeting casual programmers). > Yes, but I don't think that the specific case the

Re: __init__ style questions

2006-10-02 Thread Will McGugan
Duncan Booth wrote: > No it isn't Pythonic. Why not just require 3 values and move the > responsibility onto the caller to pass them correctly? They can still use > an iterator if they want: > > Vector3D(a, b, c) > Vector3D(*some_iter) I kind of liked the ability to partially use iterato

Re: __init__ style questions

2006-10-02 Thread Fredrik Lundh
Duncan Booth wrote: > No it isn't Pythonic. rubbish. using a single constructor that handles two common use cases is perfectly Pythonic (especially if you're targeting casual programmers). -- http://mail.python.org/mailman/listinfo/python-list

Re: __init__ style questions

2006-10-02 Thread Duncan Booth
"Will McGugan" <[EMAIL PROTECTED]> wrote: > A Vector3D can be constructed in 3 ways. If no parameters are given it > assumes a default of (0, 0, 0). If one parameter is given it is assumed > to be an iterable capable of giving 3 values. If 3 values are given > they are assumed to be the initial x,

__init__ style questions

2006-10-02 Thread Will McGugan
I am writting a Vector3D class as a teaching aid (not for me, for others), and I find myself pondering over the __init__ function. I want it to be as easy to use as possible (speed is a secondary consideration). Heres the __init__ function I have at the moment. class Vector3D(object): __slot