当前位置: 首页>>代码示例>>Python>>正文


Python Database.populate_db方法代码示例

本文整理汇总了Python中db.Database.populate_db方法的典型用法代码示例。如果您正苦于以下问题:Python Database.populate_db方法的具体用法?Python Database.populate_db怎么用?Python Database.populate_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在db.Database的用法示例。


在下文中一共展示了Database.populate_db方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process_request

# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import populate_db [as 别名]
def process_request(client,address):
	database = Database()
	
	while True:
		message = client.recv(1025)
		if message == "close":
			client.send(str(("Thanks for using this database!",0))) # second parameter is 0 - indicates that the client should terminate now like a status
			break;
		elif message == "save":
			file_name = '../Sampleinput/input_file.txt'
			db_file = open(file_name)
			mobiles_list = []
			for eachLine in db_file:
				mobiles_list.append(eval(eachLine))
			db_file.close()
			#client.send(str(("Saving data into the database! Please wait...",1)))
			database.populate_db(mobiles_list)
			client.send(str(("Database is saved!!",1)))
		else:
			database.query(message)
			with open("../Answer/results.txt","rb") as fobj:
				line = fobj.read(1024)
				while line:
					client.send(line)
					line = fobj.read(1024)
			print "sending complete"

	client.close()
开发者ID:pravardhan,项目名称:1PI10CS-50-62-32,代码行数:30,代码来源:server.py

示例2: main

# 需要导入模块: from db import Database [as 别名]
# 或者: from db.Database import populate_db [as 别名]
def main():
	print "-" * 110
	print " " * 40 + "Mobile database"
	print "-" * 110
	print """						Query format:
			- SELECT mobiles FROM 'company' WITH 'features'
			- conditions:"
			   - Companies can be any company.To search in all the companies give company name as 'all'
			   - Features must be specified as follows 
			   			'feature' operator 'value'

			   - WITH clause is mandatory
			   - To get multiple the info of mobile with two or more features seperate each feature with an 'and'
			   - Operators supported : '=', '<', '>'"
			- features 
					* operatingsystem ( only operator '=' must be used )
					* price
					* frontcamera
					* rearcamera
					* thickness
					* talktime
					* GPS ( only operator '=' must be used )
					* type ( only operator '=' must be used )

	
	Say a user wants to get the info of samsung mobiles with windows os and price less than 10000Rs and with GPS and with rearcamera\n \t The query will be
	\t\t SELECT mobiles FROM Samsung WITH operatingsystem = windows and price < 10000 and GPS = yes and rearcamera > 0"""

	
	
	start = True
	database = Database()
	while start:
		print "-" * 110
		print """					Menu"""
		print "-" * 110
		print """
				1.Save the new data into database
				2.Query the database
				3.Exit
			  """
		print "-" * 110

		choice = raw_input("Enter the choice!\n")
		if choice == '1':
			file_name = '../Sampleinput/input_file.txt'
			db_file = open(file_name)
			mobiles_list = []
			for eachLine in db_file:
				mobiles_list.append(eval(eachLine))
			db_file.close()
			print "Saving data into the database! Please wait..."
			database.populate_db(mobiles_list)
			print "Database is saved!!"
		elif choice == '2':
			query_string = raw_input("Enter the query\n")
			print "-" * 110
			database.query(query_string)
			print "-" * 110
		elif choice == '3':
			start = False
		else:
			print "Invalid choice"
开发者ID:BhuvanAnand,项目名称:1PI10CS-50-62-32,代码行数:65,代码来源:__init__.py


注:本文中的db.Database.populate_db方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。