from lib import common
def shop():
print('購(gòu)物。抑诸。台谊。')
def check_balance():
print('查看余額。八酒。空民。')
def transfer_accounts():
print('轉(zhuǎn)賬。羞迷。界轩。')
log_msg='轉(zhuǎn)賬了一個(gè)億' #定義了日志輸出
common.logger(log_msg)
def run():
msg='''
1 購(gòu)物
2 查看余額
3 轉(zhuǎn)賬
'''
while True:
print(msg)
choice=input('>>:').strip()
if not choice:continue
if choice == '1':
shop()
elif choice == '2':
check_balance()
elif choice == '3':
transfer_accounts()
另一參考版本---------------------------------
from conf import setting
# from lib import common
#
# def login():
# count=0
# while True:
# name=input('name:').strip()
# password=input('password:').strip()
# res=common.select(name)
# if name==res[0] and password==res[1]:
# print('%s 登錄成功' %name)
# else:
# print('用戶(hù)名或密碼輸入錯(cuò)誤')
# count+=1
# if count == 3:
# print('輸入錯(cuò)誤次數(shù)過(guò)多!')
# break
#
#
#
# def register():
# name = input('name:').strip()
# password = input('password:').strip()
# with open(setting.DB_PATH,'a',encoding='utf-8') as f:
# f.write('%s:%s\n' %(name,password))
# common.logger('%s 注冊(cè)成功\n' %name)
# print('注冊(cè)成功')
#
#
# def shopping():
# pass
#
# def pay():
# pass
#
# def transfer():
# pass
#
# func_dir={
# '1':login,
# '2':register,
# '3':shopping,
# '4':pay,
# '5':transfer
# }
#
#
# def run():
# while True:
# print('''
# 1 登錄
# 2 注冊(cè)
# 3 購(gòu)物
# 4 付款
# 5 轉(zhuǎn)賬
# 6 退出
# ''')
# choice=input('輸入編號(hào):').strip()
# if choice == '6':break
# if choice not in func_dir:
# print('非法輸入')
# continue
# func_dir[choice]()
common.py
# 定義日志輸出文件路徑
from conf import settings
def logger(msg):
with open(settings.LOG_PATH,'a',encoding='utf-8') as f:
f.write('%s\n' %msg)
參考另一版本------------
# import time
# from conf import setting
#
#
# def logger(msg):
# current_time=time.strftime('%Y-%m-%d %X')
# with open(setting.LOG_PATH,'a',encoding='utf-8') as f:
# f.write('%s %s' %(current_time,msg))
#
# def select(name):
# with open(setting.DB_PATH, 'r', encoding='utf-8') as f:
# for line in f:
# info=line.strip('\n').split(':')
# return info