我现在开始使用sqlalchemy.在我目前的项目中,我必须使用Flask和命令行中的其他部分做一些工作.关于烧瓶的部分运行正常,与sqlalchemy和所有的接口,但命令行部分不是.
我得到的错误是
ArgumentError("Class object expected, got 'Table('documentos',
MetaData(bind=Engine(postgresql://user:password@localhost/clasificador)),
Column('id', Integer(), table=<documentos>, primary_key=True, nullable=False),
Column('nombre', String(length=248), table=<documentos>), schema=None)'.",)
Run Code Online (Sandbox Code Playgroud)
我试过我的运气与谷歌和阅读声明性sqlalchemy,但我找不到可能是什么问题.该模块中的代码是:
from sqlalchemy.orm import sessionmaker
from db import engine,Base
#some other code
session = sessionmaker(bind=engine)
doc = modelos.documento.Documento(os.path.basename(nelto))
session.add(doc) #here fails
session.remove()
Run Code Online (Sandbox Code Playgroud)
db是我有sqlalchemy公共代码的模块.其中大部分来自于flask文档,而db_session仅用于flask,我为另一个模块创建了一个不同的会话.
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base
sqldebug=True
engine = create_engine(
'postgresql://user:passwd@localhost/clasificador',
convert_unicode=True,
echo=sqldebug)
db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base(bind=engine)
Base.query = db_session.query_property()
Run Code Online (Sandbox Code Playgroud)
最后,这里是"documento"模块,虽然我怀疑问题在这里.来自sqlalchemy导入列,整数,来自db import Base的字符串
class Documento(Base):
'''Clase definiendo los documentos''' …Run Code Online (Sandbox Code Playgroud) 我目前正在经历4clojure 问题23
我当前的解决方案使用递归遍历列表并将每个元素追加到同一函数的结果的末尾:
(fn self [x] (if (= x [])
x
(conj (self (rest x)) (first x))
))
Run Code Online (Sandbox Code Playgroud)
但是,当我对[1 2 3]运行时,它给了我(1 2 3)
我认为通过递归应该做的是:
(conj (conj (conj (conj (conj [] 5) 4) 3) 2) 1)
Run Code Online (Sandbox Code Playgroud)
它确实回来了
[5 4 3 2 1]
Run Code Online (Sandbox Code Playgroud)
但事实恰恰相反,所以我必须遗漏一些东西.另外,我不明白为什么返回一个向量而另一个返回一个列表.