我正在尝试为 RethinkDB API 制作一个包装模块,但在导入我的类(称为 rethinkdb.py)时遇到了 AttributeError。我在具有共享文件夹“Github”的虚拟机中工作。
我在 IPython 控制台中执行此操作:
import library.api.rethinkdb as re
Run Code Online (Sandbox Code Playgroud)
这是错误:
回溯(最近一次调用最后一次):
文件“”,第 1 行,在 import library.api.rethinkdb as re
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第 51 行,在 conn = Connection().connect_to_database() 中
文件“/media/sf_GitHub/library/api/rethinkdb.py”,第48行,在connect_to_database raise 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) …Run Code Online (Sandbox Code Playgroud)