Home > Net >  How to display text field based on the selected number?
How to display text field based on the selected number?

Time:11-04

I have a python code that allow user to select the number that he wants to display in a text field. The program will iterate over the range of the selected numbers and create a text field.

However, once I run the script it crashes and yields this error:

error: TypeError: cannot unpack non-iterable int object Traceback: File "F:\AIenv\lib\site-packages\streamlit\script_runner.py", line 354, in _run_script exec(code, module.dict) File "f:\AIenv\streamlit\app2.py", line 1309, in main() File "f:\AIenv\streamlit\app2.py", line 682, in main for i , old_val in range(int(number_of_replacement)):

number_of_replacement = st.number_input("Number of values To Replace",0,100)
with st.form(key='my_form'):
    col1,col2 = st.columns(2)
    st_input = st.number_input if is_numeric_dtype(df[columns]) else st.text_input

    with col1:
        for i , old_val in range(int(number_of_replacement)):
            old_val = st_input("Old value",key=i)

CodePudding user response:

Your for loop seems wrong.

Either remove the i:

with col1:
    for old_val in range(int(number_of_replacement)):
        old_val = st_input("Old value",key=i)

Or if you need the index i later on in your code enumerate over the iterable:

with col1:
    for i, old_val in enumerate(range(int(number_of_replacement))):
        old_val = st_input("Old value",key=i)
  • Related