简体   繁体   English

如何查看存储在Berkeley db中的数据库中的数据?

[英]How do i view data in database which i have stored in Berkeley db?

I am storing a values in form of dictionary in the database. 我将字典中的值存储在数据库中。 Now how do i view this data which are getting stored in this database ?? 现在我如何查看正在存储在该数据库中的数据? I want to list all the data stored in database. 我想列出存储在数据库中的所有数据。 I am using Berkeley db. 我正在使用Berkeley数据库。 And using dictionary i am storing data 并使用字典来存储数据

#!/usr/bin/python #!/ usr / bin / python

import bsddb
import cgi

form = cgi.FieldStorage()

print "Content-type:text/html\n"
Fname = form.getvalue('firstname', '')
Lname = form.getvalue('lastname', '')
Age = form.getvalue('age', 0)
Gender = form.getvalue('gender', '')

#print Fname, Lname, Age 

db = bsddb.hashopen("/home/neeraj/public_html/database/mydb.db","w")
db['FirstName'] = Fname  
db['LastName'] = Lname
db['Age'] = Age 
db['Gender'] = Gender
db.close()
db = bsddb.hashopen("/home/neeraj/public_html/database/mydb.db","r")
#db = bsddb.hashopen("/home/neeraj/public_html/database/mydb.db")
print db['FirstName'], db['LastName'], db['Age'], db['Gender']
db.close()

The same way you'd view data in a dict : by iterating it. 您在dict查看数据的方式相同:通过迭代它。

Some of the database modules, including bsddb , don't have an __iter__ method, but they all have keys . 某些数据库模块(包括bsddb )没有__iter__方法,但是它们都有keys So: 所以:

db = bsddb.hashopen("/home/neeraj/public_html/database/mydb.db","r")
for key in db.keys():
    print('{}: {}'.format(key, db[key]))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Python读取Berkeley DB文件? - How do I read Berkeley DB files with Python? 如何为Berkeley DB DBEnv指定家? - How do I specifiy the home for a Berkeley DB DBEnv? 使用 Python 和 bsddb3 在 Berkeley DB 数据库中存储数据 - Storing data in a Berkeley DB database with Python and bsddb3 如何将本地存储的表单数据传递到Django视图并将其保存在数据库中 - how can I pass locally stored form data to django view and save it on the database 如何访问和使用存储在另一个类的 init 中的类中的数据? (Python) - How do I access and use data from a class which is stored within the init of another class? (Python) 我该如何像在Python中那样执行PHP请求,以JSON格式提供数据 - How can I do a PHP request like I already have in Python which gives me data in JSON 如何根据我在 django 中制作的表单数据在 HTML 中创建卡片视图? - How do I create a card view in HTML from the form data that I have made in django? 如何将数据写入从Python中的SQL数据库获取的文件中? (sqlite3的) - How do I write data to a file that I have taken from an SQL database in Python? (sqlite3) 如何使这个plpythonu存储过程插入数据库? - How do I make this plpythonu stored procedure insert to database? 如何在具有相似值(但不相同)的公共列上合并 Pandas 中的两个数据框? - How do I merge two data frames in pandas on a common column which have similar values (but not the same)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM