value,rows = DB.DB_sel('localhost','root','ndoitadmin','Example','select * from UC1_voip_gateway')
这里我以列表格式从数据库中获取值
for j in range(0,rows):
for i in range(0,21):
# print value[j][i]
这里我必须以句子格式打印列表的值,以便我可以将变量Name传递给write.file函数将其写入文件
Name = ''' '+value[0][1]+'
list 2 = '+value[0][2]+'
.....etc ....'''
write_file.write_file(Name , Filename)
答案 0 :(得分:0)
更好地描述一下你想做什么会有所帮助,但这是我能理解的答案:
outfile = open(file.txt, 'w') # Opens the output file
for j in range(0, rows):
for i in range(0, 21) # I suppose this is the way how you obtain your "value"
outfile.write("Value1 is: %s\nValue2 is: %s" % (value[0], value[1])
第outfile.write("Value1 is: %s\nValue2 is: %s" % (value[0], value[1])
行的输出是:
Value1 is: x
Value2 is: y
for循环为数据库中的每个值执行此操作。