class db_class():
def __init__(self):
mongo_DB='test1'
self.mongo_TABEL='test'
client=pymongo.MongoClient("127.0.0.1",27017)
self.db=client[mongo_DB]
def get_path(self):
list = self.db[self.mongo_TABEL].find()
n=1
for i in list:
n += 1
print(n, i['list']) def main():
db=db_class()
db.get_path() if __name__ == '__main__':
import pymongo
main()

写入MongoDB

import os
import pymongo
mongo_DB='test1'
mongo_TABEL='test'
client=pymongo.MongoClient("127.0.0.1",27017)
db=client[mongo_DB] def dirs(dir):
files = []
list = os.listdir(dir)
for i in list:
dir1 = dir + '/' + i
if os.path.isdir(dir1):#判断是否是目录
dirs(dir1)
elif os.path.isfile(dir1):#判断是否是文件
files.append(dir1)
if files !=[]:
if '/属性图/' in files[0]:
print({'list':files})
if db[mongo_TABEL].insert_one({"list":files}):
print('插入成功',{'list':files}) def main(): dir=r'D:\xt\20181011_182016共下图2582个地址原版'.replace('\\','/')
# 先判断文件夹是否存在
if os.path.exists(dir):
print('文件夹存在')
#判断用户输入的是文件还是文件夹
if os.path.isdir(dir):
dirs(dir)
else:
print('输入的路径是文件,请输入文件夹路径...')
else:
print('文件夹不存在') if __name__ == '__main__':
main()

Python mongoDB读取的更多相关文章

  1. python+MongoDB使用示例

    本博客起源于博主的大三NoSQL课程设计,采用python+MongoDB结合方式,将数据从txt文件导入MongoDB之中,再将其取出以作图.主要技术是采用python与MongoDB结合存储读取方 ...

  2. Python MongoDB 教程

    基于菜鸟教程实际操作后总结而来 Python MongoDB MongoDB 是目前最流行的 NoSQL 数据库之一,使用的数据类型 BSON(类似 JSON). MongoDB 数据库安装与介绍可以 ...

  3. 吴裕雄--天生自然python学习笔记:Python MongoDB

    MongoDB 是目前最流行的 NoSQL 数据库之一,使用的数据类型 BSON(类似 JSON). PyMongo Python 要连接 MongoDB 需要 MongoDB 驱动,这里我们使用 P ...

  4. python下读取excel文件

    项目中要用到这个,所以记录一下. python下读取excel文件方法多种,用的是普通的xlrd插件,因为它各种版本的excel文件都可读. 首先在https://pypi.python.org/py ...

  5. Delphi中使用python脚本读取Excel数据

    Delphi中使用python脚本读取Excel数据2007-10-18 17:28:22标签:Delphi Excel python原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 . ...

  6. Python逐块读取大文件行数的代码 - 为程序员服务

    Python逐块读取大文件行数的代码 - 为程序员服务 python数文件行数最简单的方法是使用enumerate方法,但是如果文件很大的话,这个方法就有点慢了,我们可以逐块的读取文件的内容,然后按块 ...

  7. python专题-读取xml文件

    关于python读取xml文章很多,但大多文章都是贴一个xml文件,然后再贴个处理文件的代码.这样并不利于初学者的学习,希望这篇文章可以更通俗易懂的教如何使用python 来读取xml 文件. 什么是 ...

  8. python在读取文件时出现 'gbk' codec can't decode byte 0x89 in position 68: illegal multibyte sequence

    python在读取文件时出现“UnicodeDecodeError:'gbk' codec can't decode byte 0x89 in position 68: illegal multiby ...

  9. Python json 读取 json 文件并转为 dict

    Python json 读取 json 文件并转为 dict 在 D 盘 新建 test.json: { "test": "测试\n换行", "dic ...

随机推荐

  1. 【译】第10节---数据注解-Key

    原文:http://www.entityframeworktutorial.net/code-first/key-dataannotations-attribute-in-code-first.asp ...

  2. 【OJ】字符串去重并并按原顺序打印出重复字符

    ACM上一道简单的字符串题,从网上找了下类似的代码进行参考外加之个人思考,想到此好思路. 题目大意 任意输入一行字符串,检索重复出现的字符.将原字符串中的重复字符删除后按照原顺序输出,同时按照原顺序输 ...

  3. 动态 hover 使用变相使用

    使用   onmouseover  和 onmouseout 代替 hover foreach (var menu in Model.OrderBy(x => x.Order).Where(x ...

  4. 判断是否在同一个线程-GetCurrentThreadId()用法

    线程 在一个程序中,这些独立运行的程序片断叫作"线程"(Thread),利用它编程的概念就叫作"多线程处理".利用线程,用户可按下一个按钮,然后程序会立即作出响 ...

  5. React native中的组建通知通信:

    有这么一个需求,在B页面pop()回到A页面,需要A页面执行刷新,那么我们可以采用以下方法: 1:在A页面Push到B页面中,加上一个A页面中的刷新函数做为参数,然后在B页面中在pop()函数封装后通 ...

  6. mac终端不好用?用brew神器代替

    一.概念 Brew是一款Mac OS平台下的软件包管理工具,拥有安装.卸载.更新.查看.搜索等很多实用的功能.简单的一条指令,就可以实现包管理,而不用你关心各种依赖和文件路径的情况,十分方便快捷. 官 ...

  7. 理解 Redis(1) - Redis 简介

    Redis 的含义 全称: REmote DIctionary Server 远程词典服务器 由于支持 string, list, set, ordered set, hash 等多重数据结构, 因此 ...

  8. UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte sequence

    UnicodeEncodeError: 'gbk' codec can't encode character '\u25aa' in position 15: illegal multibyte se ...

  9. python (协程)生产者,消费者

    #coding=utf- import gevent from gevent.queue import Queue, Empty import time tasks = Queue(maxsize=) ...

  10. restFul接口设计规范

    1.域名 1 应该尽量将API部署在专用域名之下. https://api.example.com 2 如果确定API很简单,不会有进一步扩展,可以考虑放在主域名下. https://example. ...