How to read/processes 100 lines at a time from 10000 lines in python? -


how pass/processes 100 lines or lower try: @ time ?

receipt_dict = {} open("data.txt", "r") plain_text: // ** 10000+ lines **     line in plain_text:         hash_value = line.strip()         receipt_dict[hash_value] = 1    try:     bitcoind.sendmany("", receipt_dict) // **here must loop 100 @ time** 

with generators. here, load_data_chunks accumulates data in receipt_dict until size exceeds chunk_size , yields main loop below.

def load_data_chunks(path, fname, chunk_size):      receipt_dict = {}      open(fname, "r") plain_text:         line in plain_text:             hash_value = line.strip()             receipt_dict[hash_value] = 1              if len(receipt_dict) > chunk_size:                 yield receipt_dict                 receipt_dict = {}      yield receipt_dict  chunk in load_data_chunks("data.txt", 100):     try:         ... 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -