class or class-instance ?

S

Stef Mientki

hello,

I've a procedure (or in fact a class method) that should be callable with
either a class
(in which case the procedure should create an instance)
or with an instance of that class
as the parameter.

def somefunction ( self, parameter ) :
if parameter is a class, create an instance of that class
else do nothing



now I should be able to call the above procedure in either of the
following ways:

somefunction ( someclass )

or

somefunction ( someclass () )


thanks,
Stef Mientki
 
D

Diez B. Roggisch

Stef said:
hello,

I've a procedure (or in fact a class method) that should be callable with
either a class
(in which case the procedure should create an instance)
or with an instance of that class
as the parameter.

def somefunction ( self, parameter ) :
if parameter is a class, create an instance of that class
else do nothing



now I should be able to call the above procedure in either of the
following ways:

somefunction ( someclass )

or

somefunction ( someclass () )

There is a

isclass

in the module inspect.

Diez
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,144
Latest member
KetoBaseReviews
Top