Форум сайта python.su
0
ребят, помогите пожалуйста поправить скрипт:
import shelve db = shelve.open('data') keys = ['id', 'type', 'number']; def outputDB(db): for record in db: print(record, ': ', db[record]) for item in db[record]: print(item, '--', db[record][item]) print('-----') while 1: action = int(input('1 - print, 2 - write')) if(action == 1): outputDB(db) break else: index = input('введите индекс') db[index] = dict() for key in keys: print('enter value for ', key) value = str(input('enter value: ')) db[index][key] = value outputDB(db) db.close() print('stop')
q : {}
—–
a : {}
—–
Офлайн
23
zlodiak
import shelve db = shelve.open('data') keys = ['id', 'type', 'number']; def outputDB(db): for record in db: print db[record] print(record, ': ', db[record]) for item in db[record]: print(item, '--', db[record][item]) print('-----') while 1: action = int(input('1 - print, 2 - write')) if(action == 1): outputDB(db) break else: index = str(input('введите индекс')) db[index] = dict() newDict = dict() # в этот словать всё пишем for key in keys: print('enter value for ', key) value = input('enter value: ') newDict[key] = value db[index] = newDict # и сохраняем его outputDB(db) db.close() print('stop')
value = input('enter value: ')
Отредактировано vrabey (Янв. 20, 2014 21:26:19)
Офлайн