当我在py魅力中运行我的代码时,它显示:
__conform__()不是一个有效的Streamlit命令。“
我试图在sqlite3数据库中存储输入和结果,并将其以表格格式显示在同一流光应用程序中。
主代码页:home_task.py
import streamlit as st
from homework_db import create_table, add_data
def main():
st.title("Streamlit Exercise")
menu = ['Insert', 'Read']
choice = st.sidebar.selectbox("Menu", menu)
create_table()
if choice == 'Insert':
st.subheader('Lets check Sentiment')
line = st.text_area("Enter the sentence")
result = st.text("Positive")
if st.button("Add Task"):
add_data(line, result)
st.success("Successfully added data in database")
elif choice == 'Read':
st.subheader('Datatable')
if __name__ == "__main__":
main()另一个文件:homework_db.py
import sqlite3
conn = sqlite3.connect("homework2_db", check_same_thread=False)
c = conn.cursor()
## database-table-field-datatype##
def create_table():
c.execute('CREATE TABLE IF NOT EXISTS database(sentence TEXT, sentiment TEXT)')
def add_data(line, result):
c.execute('INSERT INTO database(sentence,sentiment) VALUES(?,?)', (line, result))
conn.commit()一切看起来都很好,我已经跟踪了很多youtube视频的sql查询,这似乎是正确的,但我不知道为什么流光不接受的代码。
我还检查了python,(https://docs.python.org/3.6/library/sqlite3.html#letting-your-object-adapt-itself),但不知道这与我的问题有什么关系。
发布于 2021-11-08 10:26:09
这是因为result不是一个字符串,而是一个Streamlit对象:
>>> import streamlit
>>> result = st.text("Positive")
>>> type(result)
<class 'streamlit.delta_generator.DeltaGenerator'>您需要做的是删除st.text()
if choice == 'Insert':
st.subheader('Lets check Sentiment')
line = st.text_area("Enter the sentence")
result = "Positive" # no st.text()
if st.button("Add Task"):
add_data(line, result)
st.success("Successfully added data in database")https://stackoverflow.com/questions/69879222
复制相似问题