On Sat, 13 Mar 2010 16:34:55 -0800, kuru wrote:

> I want this class to accept multiple data types but process them as they
> are same when the classs deals with the instances.

The usual term for this is "polymorphism".

> myvec=Vector(1,2,3)
>
> vect=[1,2,3]
> myvec=Vec(vect)

I assume you mean Vector in the last line.

I find this the easiest way to handle this situation:

class Vector(object, *args):
    if len(args) == 1:
        # Assume the caller passed a list argument.
        args = args[0]
    x, y, z = args  # Unpack the arguments.
    # then process as normal.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to