I
I
iAlex1952018-10-09 10:22:48
Python
iAlex195, 2018-10-09 10:22:48

Why is the dbfilename=dbfilename argument passed in functions?

dbfilename = 'people-file'
ENDDB  = 'enddb.'
ENDREC = 'endrec.'
RECSEP = '=>'
def storeDbase(db, dbfilename=dbfilename):
    "formatted dump of database to flat file"
    dbfile = open(dbfilename, 'w')
    for key in db:
        print(key, file=dbfile)
        for (name, value) in db[key].items():
            print(name + RECSEP + repr(value), file=dbfile)
        print(ENDREC, file=dbfile)
    print(ENDDB, file=dbfile)
    dbfile.close()
def loadDbase(dbfilename=dbfilename):
    "parse data to reconstruct database"
    dbfile = open(dbfilename)
    import sys
    sys.stdin = dbfile
    db = {}
    key = input()
    while key != ENDDB:
        rec = {}
        field = input()
        while field != ENDREC:
            name, value = field.split(RECSEP)
            rec[name] = eval(value)
            field = input()
        db[key] = rec
        key = input()
    return db
if __name__ == '__main__':
    from initdata import db
    storeDbase(db)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2018-10-09
@iAlex195

In this case, to specify which database to work with.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question