-3
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]

在这里,我必须以句子格式打印列表的值,以便我可以将变量 N​​ame 传递给 write.file 函数以将其写入文件

           Name = ''' '+value[0][1]+' 
                   list 2 = '+value[0][2]+'

                   .....etc ....'''

write_file.write_file(Name , Filename)
4

1 回答 1

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 循环对数据库中的每个值都执行此操作。

于 2012-07-24T15:01:40.937 回答