我正在尝试为RethinkDB API创建一个包装器模块,并且在导入我的类(称为rethinkdb.py)时遇到了AttributeError。我正在一个拥有共享文件夹'Github'的虚拟机中工作。
我在IPython控制台中这样做:
import library.api.rethinkdb as re
这是错误:
Traceback(最近一次调用最后一次):
文件“”,第1行,导入library.api.rethinkdb为re
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第51行,conn = Connection()。connect_to_database()
在connect_to_database中的文件“/media/sf_GitHub/library/api/rethinkdb.py”,第48行引发e
AttributeError:'module'对象没有属性'connect'
这是代码:
import rethinkdb as r #The downloaded RethinkDB module from http://rethinkdb.com/
class Connection(object):
def __init__(self, host='127.0.0.1', port=28015, database=None, authentication_key=''):
self.host = host
self.port = port
if database is None:
self.db = 'test'
self.auth_key = authentication_key
def connect_to_database(self):
try:
conn = r.connect(self.host, self.port, self.db, self.auth_key)
except Exception, e:
raise e
return conn
conn = Connection().connect_to_database()
我今天碰到了类似的东西,我注意到作者在更高版本中改变了API的基本行为。
从我在我的机器上测试的:
V2.3.0
import rethinkdb as r
r.connect()
V2.4.1
import rethinkdb as r
rdb = r.RethinkDB()
rdb.connect()
我跑的时候对我有用:
import rethinkdb as rdb
r = rdb.RethinkDB()
r.connect('localhost', 28015).repl()