在python中函数不可以嵌套调用_Python:在嵌套函数调用中应用列表

我有两个def函数,我以嵌套的方式调用,并想在循环中调用第二个函数。我目前只能找出如何手动调用我的列表的语法,而不是应用列表中的每个成员...

#A list of the files I want to read

afiles = [['awc_mm09c.txt','integer'], ['canopy01c.txt','real'],

['canopy10c.txt','real'], ['canopy33c.txt','real'],

['ccapnyp6c.txt','text'], ['gclass09c.txt','text'],

['nyelev09c.txt','real']]

def readfile(fn):

conn = open(ascPath + '\\' + fn, 'r')

# code to read data from the file

def rows(*columns):

# code that merges data from the other files into columns

for ID, cols in enumerate(itertools.izip(*columns)):

yield [ID] + list(cols)

# build the SQL

strQuery = "insert into foo...;"

# run some apsw (SQLite) code

c.execute("begin")

# this works. Is there any way to avoid manually listing each item in the list?

c.executemany(strQuery, rows(readfile(afiles[0][0]),

readfile(afiles[1][0]),

readfile(afiles[2][0]),

readfile(afiles[3][0]),

readfile(afiles[4][0]),

readfile(afiles[5][0]),

readfile(afiles[6][0])))

c.execute("commit")

#I've tried something like the following, but to no avail:

c.executemany(strQuery, rows(

for f in range(len(afiles_dt)):

readfile(afiles_dt[f][0])))提前致谢。蒂姆

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值