【发布时间】:2012-03-24 04:56:07
【问题描述】:
我正在尝试更多地了解 Python 中的 .egg 概念和覆盖方法。这是我收到的错误消息:
Traceback (most recent call last):
File "C:/local/work/scripts/plmr/plmr_db.py", line 42, in <module>
insp.reflecttable(reo_daily_table, column_list)
File "build\bdist.win32\egg\sqlalchemy\engine\reflection.py", line 370, in reflecttable
File "build\bdist.win32\egg\sqlalchemy\engine\reflection.py", line 223, in get_columns
File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 260, in get_columns
NotImplementedError
下面是 base.py 中的具体函数:
def get_columns(self, connection, table_name, schema=None, **kw):
"""Return information about columns in `table_name`.
Given a :class:`.Connection`, a string
`table_name`, and an optional string `schema`, return column
information as a list of dictionaries with these keys:
name
the column's name
type
[sqlalchemy.types#TypeEngine]
nullable
boolean
default
the column's default value
autoincrement
boolean
sequence
a dictionary of the form
{'name' : str, 'start' :int, 'increment': int}
Additional column attributes may be present.
"""
raise NotImplementedError()
所以我的问题是 - 我是否通过在我的主模块中编写一个新方法来覆盖这个函数?还是我在导入的过程中遗漏了一步?还是我完全偏离了轨道?
感谢您的任何帮助:)
编辑:添加我的代码
import sys
from sqlalchemy import create_engine, select, Table, MetaData
from sqlalchemy.engine import reflection
dbPath = 'connection_string'
engine = create_engine(dbPath, echo=True)
connection = engine.connect()
#reflect tables into memory
meta = MetaData()
reo_daily_table = Table('reo_daily',meta)
insp = reflection.Inspector.from_engine(engine)
column_list=[...]
insp.reflecttable(reo_daily_table, column_list)
connection.close()
【问题讨论】:
-
我们对您编写的代码一无所知,因此我们不知道您哪里出错了。我们可以推测,但在我们真正看到一些代码之前(最好是一个足以重现错误的最小示例),我们所能做的就是在黑暗中拍摄。
-
添加了我的代码,感谢您的建议
-
问题完全错误;你不应该需要继承或覆盖那里的任何东西。您只是错误地使用了 SQLAlchemy。
-
有了表反射,实际的数据库连接非常重要。
'connection_string'不可能有效。此外,column_list=[...]不是有效的 python。您可以将连接 url 的“username:password@host/db”部分替换为假人,但我们确实需要您的实际代码 -
@TokenMacGuy 我的 dbPath 是有效的,我能够很好地连接到数据库 - 不想公开发布服务器名称、用户名、密码等。至于列列表,它也是填充了有效的 Python。 e:这里是连接字符串的格式:'sybase+pysybase://user:pass@server_dsn/tablename'
标签: python sqlalchemy overriding egg