Feeding differeent data types to a class instance?
steve at REMOVE-THIS-cybersource.com.au
Sun Mar 14 02:27:56 CET 2010
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".
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
x, y, z = args # Unpack the arguments.
# then process as normal.
More information about the Python-list