St.write prints class bytes instead of actual value

I created a for loop that loops through a text file and appends each line to a list. but when I try to display this list with st.write I keep getting “class bytes” instead of the actual value

This is the code
feat_cols

And this is the result

Hi,

The docs for file_uploader explain that the return type is a subclass of BytesIO, and therefore should be processed as if it is file-like. See here.

For a text file with this content:

test.txt

feature_1
feature_2
feature_3
feature_4
feature_5

This program will return the list as expected:

test.py

import streamlit as st
from io import StringIO

uploaded_file =  st.file_uploader('', type='txt', accept_multiple_files=False)
if uploaded_file:
    stringio = StringIO(uploaded_file.getvalue().decode('utf-8'))
    features = [feature.strip() for feature in stringio.readlines()]
    st.write(features)

Run

streamlit run test.py

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8765
  Network URL: http://192.168.1.10:8765

Output

1 Like