在Python代码中,通过for循环中的select获取值后,我必须获取索引[0]的第个值

在Python代码中,通过for循环中的select获取值后,我必须获取索引[0]的第个值,python,oracle,Python,Oracle,'我编写的代码' ''' ''' '从这个select语句中,我想获取主机名的值,并将该值附加到filename.txt。文件名应该是这样的' '''samplefile-datetime-hostname''' “如何解决这个问题?”可能类似于: crsr.execute("select hostname, employee_add1, employee_add2 from dual") records = crsr.fetchmany(size) for h,a1,a2

'我编写的代码' '''

''' '从这个select语句中,我想获取主机名的值,并将该值附加到filename.txt。文件名应该是这样的'

'''samplefile-datetime-hostname'''
“如何解决这个问题?”

可能类似于:

crsr.execute("select hostname, employee_add1, employee_add2 from dual")
records = crsr.fetchmany(size)
for h,a1,a2 in records:
     print(h+"-samplefile.txt")
不清楚您是要总共打开一个文件,还是每个表行打开一个文件,但您可以轻松地在循环外部或内部添加一个
open()

您还可以导入
datetime
,并获取要连接到字符串中的日期


您可能希望从主机名列值中去掉前导和尾随空格。

从执行的获取结果中,我正在执行两个操作,一个是将主机名和UTC日期时间添加到文件名中,我将使用正则表达式用二进制分隔符分隔键值。如果您有困难,使用代码的当前状态更新问题文本,并优化问题。
crsr.execute("select hostname, employee_add1, employee_add2 from dual")
records = crsr.fetchmany(size)
for h,a1,a2 in records:
     print(h+"-samplefile.txt")