jeudi 23 avril 2015

Python High Order Function IF ELSE check

I've an object with a function as one of its variables that can be kind1 or of kind2. These functions are in an other imported file and are passed to its constructor which is obviously an high order function (a function that takes a function as input). Once that I've created the object I can access the associated function with object.function Now I want to perform some checks on the object and I want to discriminate wheter its function is of kind1 or of kind2.

I've tried with

if object.function == kind1:
    print 'kind1'
elif object.function == kind2:
    print 'kind2'

and with

if object.function == kind1():
    print 'kind1'
elif object.function == kind2():
    print 'kind2'

it doesn't work because kind1, kind2 or kind1(), kind2() are not defined...what's wrong?

Aucun commentaire:

Enregistrer un commentaire