Experimenting with ex43.py (make a game) from LearnPythonTheHardWay and using time.sleep()
to create pauses between events. In order to enable and disable the feature, or change the length of the pauses, I am just holding a variable in class Engine()
, which is referenced from the calls to time.sleep()
throughout the program.
So:
import time
class Engine(object):
sleep1 = 1
#some methods
def say_hello(self, exit):
self.exit = exit
print "Hello"
time.sleep(Engine.sleep1)
self.exit.say_goodbye()
class Another(object):
def say_goodbye(self):
print "ok"
time.sleep(Engine.sleep1)
print "goodbye."
me = Engine()
bye = Another()
me.say_hello(bye)
The question is, if I want time.sleep(1)
to be available to multiple methods of various classes, does it need to be passed to each method that needs it as a parameter like this:
import time
class Engine(object):
sleep1 = 1
#some methods
def say_hello(self, exit):
self.exit = exit
print "Hello."
time.sleep(Engine.sleep1)
pause = time.sleep
self.exit.say_goodbye(pause)
class Another(object):
def say_goodbye(self, pause):
self.pause = pause
print "ok"
self.pause(Engine.sleep1)
print "goodbye."
me = Engine()
bye = Another()
me.say_hello(bye)
And in order to have just one place in which to set the length of the pause, is there an improvement on simple calling time.sleep(Class.var)
from whatever method?