中国开发网: 论坛: 程序员情感CBD: 贴子 797309
leejd
看文档没明白,看一下源码就知道了
原来是跟pymongo并行的,不是那个包下面的

import sys

from pymongo.connection import Connection
from pymongo.errors import ConnectionFailure
import gridfs

# Make a connection to Mongo.
try:
connection = Connection("localhost", 27017)
except ConnectionFailure:
print "couldn't connect: be sure that Mongo is running on localhost:27017"
sys.exit(1)

# We need a database for GridFS to use, but first make sure it's clean.
connection.drop_database("pymongo_examples")
db = connection["pymongo_examples"]

# Create our GridFS instance
fs = gridfs.GridFS(db)

# Open a GridFile for writing, and write some content
f = fs.open("hello.txt", "w")
f.write("hello ")
f.write("world")
f.close()

# Now print the contents of the file
g = fs.open("hello.txt")
print g.read()

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录