【Python基础】我的第一个 python 程序

返回: Python基础 索引页

这个python 程序,只是一个空壳,可以用来进行简单的交互测试。

import sys,shelve

def enter_cmd():
    cmd = input('Please enter the cmd(? for help): ')
    cmd = cmd.strip().lower()

    return cmd

def print_help():
    '存储(增加)、查找、更新(修改)、循环打印、删除、退出、帮助'
    print('The available commons are: ')
    print('quit     : Save changes and exit')
    print('?        : Print this message')


def main():
    database = shelve.open('database20210915001.dat', writeback=True)
    try:
        while True:
            cmd = enter_cmd()
            if cmd == '?':
                print_help()
            elif cmd == 'coordinate':
                enter_coordinate()
            elif cmd == 'quit':
                return
    finally:
        database.close()

if __name__=='__main__':
  main()

运行方法:

上述代码保存在 与 python.exe 同目录下,命名为 MyWorld000.py

点击 python.exe ,在>>> 提示符,输入 import MyWorld000

然后再在 >>> 提示符,输入 MyWorld000.main 即可。

运行结果:

>>> MyWorld000.main()
Please enter the cmd(? for help): ?
The available commons are:
quit     : Save changes and exit
?        : Print this message
Please enter the cmd(? for help): quit
>>>

输入 quit 后,退出。

返回: Python基础 索引页

posted @ 2021-09-15 08:18  健哥的数据花园  阅读(167)  评论(0编辑  收藏  举报