简体   繁体   English

Python time.sleep() DRY 问题

[英]Python time.sleep() DRY issue

i am making a tiny terminal game.我正在制作一个小型终端游戏。 based of many text with yes/no questions and i must use "time.sleep()" many times for delay effect.基于许多带有是/否问题的文本,我必须多次使用“time.sleep()”来获得延迟效果。 i try to follow the DRY(Dont Repeat Yourself) principle.我尝试遵循 DRY(不要重复自己)原则。 how can i avoid using this method many times?我怎样才能避免多次使用这种方法?

print('some texts')
time.sleep(1)

if True:
   print('some texts')
   time.sleep(1)

print('some texts')
time.sleep(1)

You can encapsulate your print and time.sleep calls into a function that you define which accepts a string (to print) and an integer (to pass to time.sleep)您可以将您的printtime.sleep调用封装到您定义的 function 中,它接受字符串(用于打印)和 integer(用于传递给 time.sleep)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM