如何根据所选数字显示文本字段?
How to display text field based on the selected number?
我有一个 python 代码,允许用户 select 他想在文本字段中显示的数字。该程序将遍历 selected 数字的范围并创建一个文本字段。
但是,一旦我 运行 脚本崩溃并产生此错误:
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)
您的 for 循环似乎有误。
要么删除 i
:
with col1:
for old_val in range(int(number_of_replacement)):
old_val = st_input("Old value",key=i)
或者如果您稍后在代码中需要索引 i
enumerate
在可迭代对象上:
with col1:
for i, old_val in enumerate(range(int(number_of_replacement))):
old_val = st_input("Old value",key=i)
我有一个 python 代码,允许用户 select 他想在文本字段中显示的数字。该程序将遍历 selected 数字的范围并创建一个文本字段。
但是,一旦我 运行 脚本崩溃并产生此错误:
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)
您的 for 循环似乎有误。
要么删除 i
:
with col1:
for old_val in range(int(number_of_replacement)):
old_val = st_input("Old value",key=i)
或者如果您稍后在代码中需要索引 i
enumerate
在可迭代对象上:
with col1:
for i, old_val in enumerate(range(int(number_of_replacement))):
old_val = st_input("Old value",key=i)