Edmund 程式設計歷程
此網誌為Edmund程設學習歷程,Code多為網路上與書本轉載而來,如有犯法請告知,必立馬刪除.
2013年1月28日 星期一
在python 中 使用mongoDB 像mysql 一樣取出陣列資料
最近遇到的問題, python 中直接直接使用mysql querry 出來的資料可以用陣列的方式取得, 那 mongo呢?
直接來看代碼
...
...
...
accounts = accounts.find_one({'username':'axdc11239@yahoo.com.hk'})
print accounts
print list(accounts)
print list(accounts)[0]
閱讀更多 »
2013年1月27日 星期日
在python中把string當成object.name
因為最近有需要用到,碰巧看到人家python有出現這樣的代碼 getattr(... , ...)
http://blog.csdn.net/wzm112/article/details/6444668
def
query():
conn = Connection(
'127.0.0.1'
,
27017
)
db = getattr(conn,
'dbname'
)
coll = getattr(db,
'collname'
)
#使用正则查询
import
re
q = rs.compile(r
'add'
)
#完成正则 r'.*' ,r'[a-z]+'
rst = coll.find({
'field'
: {
'$regex'
: q } })
print
rst.count()
#打印查询结果
#查询方式2
rst = coll.find({
'field'
: {
'$regex'
: r
'[a-z]+'
} })
print
rst.count()
閱讀更多 »
較新的文章
較舊的文章
首頁
訂閱:
文章 (Atom)