Feeding differeent data types to a class instance?

kuru maymunbeyin at gmail.com
Sun Mar 14 01:34:55 CET 2010


Hi

I have couple classes in the form of

class Vector:
  def __init__(self,x,y,z):
   self.x=x
   self.y=y
   self.z=z

This works fine for me. However I want to be able to provide a list,
tuple as well as individual arguments like below

myvec=Vector(1,2,3)

This works well


However I  also want to be able to do

vect=[1,2,3]

myvec=Vec(vect)

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

thanks





More information about the Python-list mailing list