简体   繁体   中英

How to maintain multiple lists in CSV file and how to read it using python

I am running test cases using python. For my scenarios I need to have multiple lists in CSV file and read them one by one. For now I am working with single list per CSV file and because of that I am having lot of csv files. Could you pls help on this?

my desired CSV file is like below containing more then one list:

bundleParentId;id;itemType;itemNo;requiredQty;unitOfMeasure
 ;2;ART;20318823;2;Piece
 ;3;ART;00258882;2;Piece
 ;4;ART;40401840;2;Piece

bundleParentId;id;itemType;itemNo;requiredQty;unitOfMeasure
 ;2;ART;20318823;2;Piece

bundleParentId;id;itemType;itemNo;requiredQty;unitOfMeasure
 ;2;ART;20565823;2;Piece
 ;3;ART;00259876;2;Piece

bundleParentId;id;itemType;itemNo;requiredQty;unitOfMeasure
 ;2;ART;67543898;2;Piece
 ;3;ART;13432343;2;Piece
 ;4;ART;00972444;2;Piece
 ;5;ART;00258882;2;Piece
 ;6;ART;40401840;2;Piece

It sounds like you might want to use something like TinyDB . TinyDB allows you to make a simple database structure that works like a flat dictionary. A TinyDB object can handle multiple databases all stored in a single flat(ish) JSON file.

Each row in the DB is aware of it's content and can be easily queried, deleted and upserted.

It's as simple as this to create, insert a record and query a DB:

>>> from tinydb import TinyDB, Query
>>> db = TinyDB('path/to/db.json')
>>> User = Query()
>>> db.insert({'name': 'John', 'age': 22})
>>> db.search(User.name == 'John')
[{'name': 'John', 'age': 22}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM