我有一个代码,它将查询结果保存到csv文件。是否可以根据查询结果创建条件?例如:
如果查询结果包含字符串“”,则执行另一个查询并将其保存到现有文件.
我应该用“取球”方法吗?
我的代码:
try:
connection = cx_Oracle.connect('TAGATE','TAGATE','GPSPL')
cursor = connection.cursor()
print "connected"
try:
query = """select example1 , example 2 from dbo1""".format(line_name)
tmp = cursor.execute(query)
columns = [i[0] for i in cursor.description]
results = tmp.fetchall()
cursor.close()
except:
pass
except:
print IOError
filename='{0}.csv'.format(line_name)
if results:
csv_file = open(filename,'wb')
myFile = csv.writer(csv_file)
myFile.writerow(columns)
myFile.writerows(results)
#i think another statment should be here发布于 2015-09-16 12:55:28
我会做以下几件事:
...
if results:
for ex1, ex2 in results:
# I assumed string was to be found in field 'Example1'
if 'Test' in ex1:
# Save your results as you do with csv_file = open(filename,'wb') and so onhttps://stackoverflow.com/questions/32606631
复制相似问题