【发布时间】:2019-05-08 00:12:09
【问题描述】:
我想在 sqlalchemy 中使用过滤功能获取我的用户密码,但它返回的格式错误。这是什么原因?
这是我的数据库: 用户名:asdef 密码:1234
engine = create_engine('sqlite:///',echo=True)
Base = declarative_base()
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True)
username = Column(String(50))
password= Column(String(50))
name=Column(String(50))
surname=Column(String(50))
Session = sessionmaker(bind=engine)
session = Session()
for password in session.query(User.password).filter(User.username=='asdef'):
print (password)
session.commit()
我希望输出 '1234' 但实际输出是 ('1234',)
【问题讨论】:
-
我认为以上内容不一定重复的原因是我不相信 OP 真的希望从查询中返回多行。如果我是对的,那么
.scalar()绝对是返回值的最简洁的方法,并且该问题中的答案都没有提到它。如果我错了,那么是的,它是重复的。
标签: python sqlalchemy