motor的使用
Posted c-x-a
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了motor的使用相关的知识,希望对你有一定的参考价值。
# -*- coding: utf-8 -*-
# @Time : 2018/11/18 10:41 PM
# @Author : cxa
# @File : motordb.py
# @Software: PyCharm
import asyncio
try:
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
except ImportError:
pass
from motor.motor_asyncio import AsyncIOMotorClient
class MotorBase:
_db = {}
_collection = {}
def __init__(self, loop=None):
self.motor_uri = ‘‘
self.loop = loop or asyncio.get_event_loop()
def client(self, db):
self.motor_uri = f"mongodb://localhost:27017/{db}"
return AsyncIOMotorClient(self.motor_uri, io_loop=self.loop)
def get_db(self, db=‘test‘):
if db not in self._db:
self._db[db] = self.client(db)[db]
return self._db[db]
async def savedata():
mb = MotorBase().get_db(‘test‘)
await mb.news.insert_one({‘name‘: "lisa"})
if __name__ == ‘__main__‘:
loop = asyncio.get_event_loop()
loop.run_until_complete(savedata())
以上是关于motor的使用的主要内容,如果未能解决你的问题,请参考以下文章
Danfoss Motor - Automotive Motor Linerless Technology: Surface Roughening
MakeCode EV3 电机反转不适用于 motor.xx.tank