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
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.
>
>
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
"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)
>
"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
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
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
"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,
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