Hello , I have tried text_input and text_area and saving them into a session state.
However , when i try to pull our from that session state in for loop method.
it always put a single string for me.
for exaple: when i enter “apple” in text_input.
and i get 「a,p,p,l,e」
is there any solution? thanks
Could you clarify or provide example of the intended output that you’d like to see. A diagram would be helpful.
You’re looping through a string, which will give you one character at a time – you don’t need a loop, just get the item and print it. Here are two ways to accomplish that:
import streamlit as st
text = st.text_input("Text input", key="text_input")
Hello, thanks for your answer, if i want to put more than 2 string in a ‘session_state’ , and iterate the session_state, is there any way to get that? thanks!!
st.session_state[‘key’] = ‘apple’ , ‘grape’
for i in st.session_state[‘key’]:
I want to get ‘apple’, ‘grape’, not seperated string such as ‘a’,‘p’,‘p’,‘l’,‘e’
st.session_state['key'] = [‘apple’ , ‘grape’]
for i in st.session_state['key']:
If it’s a list, that will work just fine
If it’s just a giant string, separated with commas:
st.session_state['key'] = ‘apple, grape’
for i in st.session_state['key'].split(', '):
Thanks! the best answer !!!
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.