if __name__ == '__main__':
option = raw_input("input:")
if option == "start":
print("start app")
elif option == "stop":
print("stop app")
elif option == "restart":
print("restart app")
def start_app():
print("start app")
def stop_app():
print("stop app")
def restart_app():
print("restart app")
switch = {
"start": start_app,
"stop": stop_app,
"restart": restart_app
}
if __name__ == '__main__':
option = raw_input("input:")
switch[option]()
本系列文章和代码已经作为项目归档到github,仓库地址:jumper2014/PyCodeComplete。大家觉得有帮助就请在github上star一下,你的支持是我更新的动力。什么?你没有github账号?学习Python怎么可以没有github账号呢,快去注册一个啦!