Upload text file which needs to be read line by line

I need to upload a text file, which I need to read line by line to extract data with string functions.
While I am able to upload the file and convert it to bytes or string , I am losing the capability to read line by line in the original format of the text file.
Is there a way out?

Hi @Indranil_Mallick,

You won’t loose the capability to read line by line :slight_smile:
You can directly use readline method or just iterate over lines using a for loop,

import streamlit as st

uploaded_file = st.file_uploader("Add text file !")
if uploaded_file:
    for line in uploaded_file:
1 Like

Thanks a ton. I was unnecessarily trying to read/open the uploaded file and running into problems.
I noticed that the line is a bytes object, and first need to convert it to a string to perform string operations on them.