我對pymongo很陌生。在下面的代碼,'module'對象在pymongo中沒有屬性'OrderedDict'錯誤
db = MySQLdb.connect(DB_HOST,DB_USR,DB_PWD,DB_NAME)
cursor = db.cursor()
query = "SELECT * FROM %s WHERE userid = \"%s\"" % (table, userID)
cursor.execute(query)
colNames = [i[0] for i in cursor.description]
rows = cursor.fetchall()
objects_list = []
# The below logic makes JSON objet based on fetch MySQL rows.
for row in rows:
d = collections.OrderedDict()
index = 0
for col in colNames:
d[col] = row[index]
index = index + 1
objects_list.append(d)
return objects_list
,我發現了錯誤,
trngl_advertise_perfm
trngl_advertise_activity
trngl_user_fblike
Traceback (most recent call last):
File "IngestDataToMongo.py", line 83, in <module>
userData = getData(user[0], TABLES[i]) # Get data of each user.
File "IngestDataToMongo.py", line 51, in getData
d = collections.OrderedDict()
AttributeError: 'module' object has no attribute 'OrderedDict'
請告訴我,如何刪除錯誤。
檢查您的Python版本 –
@InbarRose我無法更改我的python版本,因爲代碼位於服務器上運行的腳本中。那麼有沒有像導入文件或其他我可以用來代替OrderedDict的東西的選項。 –