Using two session state variables not working

The program doesn’t work when I am trying to create two session state variables.

import streamlit as st
import SessionState

select_symbol = ['FIRST','SECOND','THIRD','FOURTH','FIVETH'] 
#used as options for symbol_input container's selectbox

#------------Initializing Two Session states------------
current_list = []
ss1 = SessionState.get(current_list=current_list)
#use ss1.current_list everywhere now

final_list = []
ss2 = SessionState.get(final_list=final_list)
#use ss2.final_list everywhere now


#------------ Create Containers----------------
watchlist_container = st.beta_container()
order_container = st.beta_container()

with watchlist_container:
    st.header('Watchlist')
    
    symbol_input = st.beta_container()
    sym = symbol_input.selectbox('Choose Symbols', options=select_symbol)
    
    
    buttons = st.beta_container()
    with buttons:
        # three buttons to add, delete, done
        add_button, delete_button, done_button  = st.beta_columns(3)
        add = add_button.button('add')
        delete = delete_button.button('delete')
        done = done_button.button('done')


if add:
    ss1.current_list.append(sym)
if delete:
    ss1.current_list.remove(sym)
st.write(ss1.current_list)

#Click on done saves current list to final list
if done:
    ss2.final_list.append(ss1.current_list)
    
    
with order_container:
    st.header('Order Here')
    # select a value from ss2.final_list
    selected = order_container.selectbox('order symbol', options=ss2.final_list)
    
    #Show final_list
    st.write(ss2.final_list)
    #Show selected value from final_list
    st.write(selected)

The above code is giving an attribute error:
AttributeError: ‘SessionState’ object has no attribute ‘final_list’

Hey @Prakhar_Gupta ,
You can initialize final_list inside your first session state variable and call it from ss1 like ss1.final_list:

ss1 = SessionState.get(current_list=current_list, final_list=[])

Just change ss2.final_list with ss1.final_list

Let us know if that was helpful !

1 Like

Yes this worked now. Thanks @nainiayoub