Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

reading a file line by line using a generator

def read_file(path, block_size=1024): 
    with open(path, 'rb') as f: 
        while True: 
            piece = f.read(block_size) 
            if piece: 
                yield piece 
            else: 
                return

for piece in read_file(path):
    process_piece(piece)
Comment

PREVIOUS NEXT
Code Example
Python :: tkinter frameless window 
Python :: installing private python packages from requirements.txt 
Python :: Update modules within the requirements.txt file 
Python :: arrayfield django example 
Python :: pip install opencv 
Python :: os.move file 
Python :: How to install packages offline? Ask Question 
Python :: python for android 
Python :: py to exe 
Python :: how to encode emoji to text in python 
Python :: download folder collab 
Python :: get unique values from a list 
Python :: flatten a list 
Python :: How to import HTML code into python with selenium webdriver 
Python :: how to make an array in python 
Python :: pandas dataframe display cell size 
Python :: python string in list 
Python :: how to hide ticks in python 
Python :: python image layers 
Python :: read pickle file 
Python :: delete and start fresh with db django 
Python :: spyder new instance 
Python :: convert integer to binary in python 
Python :: python mongodb schema 
Python :: dataframe shift python 
Python :: DJANGO rest framework GET POST 
Python :: django bootstrap 
Python :: how to center a string python 
Python :: df groupby 
Python :: Converting Dataframe from list Using a list in the dictionary 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =