N
N
NaitonOlgran2018-02-11 23:07:40
Python
NaitonOlgran, 2018-02-11 23:07:40

How to run a function through self?

Help with such a problem, how to assign a value to a function in self, and then call it in another?
And how to pass values ​​​​to a function when creating it without calling it?

class create:
  def person(self, name, handler):
    self.name = name
    self.handler = handler <--- Здесь проблема
    return self

  def start(self):
    self.handler()
    print("Started")

class make:
  def Simple(self,type):
    self.type = type
    print("send %s" % self.type)

mage = make().Simple("Ogr") <--- Как задать здесь аргумент для self без вызова функции.
man = create()
man.person("Dukalis", mage)
man.start() <--- Как при запуске этой функции сделать так, чтобы запустилась и функция Simple?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rennorb, 2018-02-12
@NaitonOlgran

class create:
  def __init__(self, name, handler):
    self.name = name
    self.handler = handler

  def start(self):
    self.handler()
    print("Started")

  def hw():
    print('hello world')

  create('hello', hw).start()

And it's really worth reading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question