use functions in a class - python -
i have couple of functions defined in code , want able call them in 1 of class. want pass 1 of name argument can select right function call in class.
i looked such things on internet found how call function defined in class inside same or class. can't define functions inside class because call other functions
so there's not there's code :
class _fonction_use_: def __init__(self,pos,function): self.pos=pos self.function=function
where "function" name of 1 of functions defined outside class.
so, if fonction_use belong class, want fonction_use.function return function assigned before.
since functions first class objects, can pass them directly class.
def somefunc(): pass # class myclass(object): def __init__(self, pos, function): self.pos = pos self.function = function myclass = myclass(0, somefunc)
Comments
Post a Comment