St.write of list elements show a prefix. How to remove the prefix

I have a stremlit app that runs

results = subprocess.check_output(["Rscript", "latest_updates.R"])
st.write(results)

and returns:

b'[[1]]\r\n \r\n1 2023-03-09T12:19:34.3653038Z\r\n\r\n[[2]]\r\n \r\n1 2023-03-09T12:19:33.1931475Z\r\n\r\n[[3]]\r\n \r\n1 2023-03-02T17:12:01.3036067Z\r\n\r\n[[4]]\r\n \r\n1 Mar 9 2023 1:45PM\r\n\r\n[[5]]\r\n \r\n1 2023-03-02T17:08:18.1044511Z\r\n\r\n[[6]]\r\n \r\n1 <NA>\r\n\r\n[[7]]\r\n \r\n1 2023-03-09T10:24:21.1608589Z\r\n\r\n'

this is a list that contains 7 timestamps from R.

I convert this to a list with:

r = results.decode("utf-8").replace("\r\n\r\n","").replace("\r\n \r\n1 ","").replace("[[1]]","").replace("[[2]]","|").replace("[[3]]","|").replace("[[4]]","|").replace("[[5]]","|").replace("[[6]]","|").replace("[[7]]","|").split("|")

and write each element to streamlit with:

st.write(r[0])
st.write(r[1])
st.write(r[2])
st.write(r[3])
st.write(r[4])
st.write(r[5])
st.write(r[6])

The data are ok, but on the app itself, each string is prefixed with a 1 , and I would like to remove that:

enter image description here

Any suggetions? TIA

You can slice the strings to remove a fixed number of characters up front:

x = '1 2023-01-01'
y = x[2:]

Or you can remove a set string of characters

x = '1 2023-01-01'
y = x.removeprefix('1 ')

I put your fragments together in a streamlit app like this:

import streamlit as st

results = b'[[1]]\r\n \r\n1 2023-03-09T12:19:34.3653038Z\r\n\r\n[[2]]\r\n \r\n1 2023-03-09T12:19:33.1931475Z\r\n\r\n[[3]]\r\n \r\n1 2023-03-02T17:12:01.3036067Z\r\n\r\n[[4]]\r\n \r\n1 Mar 9 2023 1:45PM\r\n\r\n[[5]]\r\n \r\n1 2023-03-02T17:08:18.1044511Z\r\n\r\n[[6]]\r\n \r\n1 <NA>\r\n\r\n[[7]]\r\n \r\n1 2023-03-09T10:24:21.1608589Z\r\n\r\n'
r = results.decode("utf-8").replace("\r\n\r\n","").replace("\r\n \r\n1 ","").replace("[[1]]","").replace("[[2]]","|").replace("[[3]]","|").replace("[[4]]","|").replace("[[5]]","|").replace("[[6]]","|").replace("[[7]]","|").split("|")

st.write(r[0])
st.write(r[1])
st.write(r[2])
st.write(r[3])
st.write(r[4])
st.write(r[5])
st.write(r[6])

And this is what I get;

2023-03-09T12:19:34.3653038Z

2023-03-09T12:19:33.1931475Z

2023-03-02T17:12:01.3036067Z

Mar 9 2023 1:45PM

2023-03-02T17:08:18.1044511Z

<NA>
2023-03-09T10:24:21.1608589Z

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.