看上去两者是一样的。但是是有区别的。区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
比如今天困扰我的一个简单问题,
报错sqlalchemy.exc.ArgumentError: Argument 'class_' is expected to be of type '<type 'type'>', got '<type 'module'>'
或报错TypeError: 'module' object is not callable
正常通过。或者
正常通过
比如今天困扰我的一个简单问题,
import User
usermapper = mapper(User,users_table)报错sqlalchemy.exc.ArgumentError: Argument 'class_' is expected to be of type '<type 'type'>', got '<type 'module'>'
或报错TypeError: 'module' object is not callable
from User import *
usermapper = mapper(User,users_table)正常通过。或者
import User
usermapper = mapper(User.User,users_table)正常通过
本文探讨了在使用Python的SQLAlchemy库进行对象关系映射(ORM)时遇到的问题。特别是当使用import语句从不同模块导入类时的区别。文章通过实例说明了如何正确地将类映射到数据库表。
1203

被折叠的 条评论
为什么被折叠?



