Python和CSV文件中的嵌套循环 [英] Nested loops in Python and CSV file

查看:91
本文介绍了Python和CSV文件中的嵌套循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌套了for循环的python lambda

I have a python lambda with nested for loop

def lambda_handler(event, context):
    acc_ids = json.loads(os.environ.get('ACC_ID'))
    with open('/tmp/newcsv.csv', mode='w',  newline='') as csv_file:
        fieldnames = ['DomainName', 'Subject', 'Status', 'RenewalEligibility', 'InUseBy']
        writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
        writer.writeheader()
        for acc_id in acc_ids:
            try:
                //do something
                for region in regions_to_scan:
                    try:
                       // do something
                        if something:
                            for x in list:
                                // get values for row
                                writer.writerow('write rows here')
                        
                    except Exception as e:
                        print(e)
                        continue 
            except Exception as e:
                print(e)
                continue
    s3 = boto3.client('s3')
    response = s3.upload_file('/tmp/newcsv.csv', 'my-bucket', 'newcsv.csv')

这不是在S3中上载文件,从其他对话中,我确保了在写上下文完成后上载了文件.有人可以评估我的脚本吗?

This is not uploading the file in S3, from other conversations I made sure that the uploading of the file is after the writing context is done. Can someone evaluate my script?

推荐答案

转出循环,lambda是正确的. lambda函数的超时设置为10秒,并且从未到达上传文件的代码.增加lambda的超时可以解决我的问题

Turns out the loop and the lambda were correct. The timeout on the lambda function was set to 10 secs and it never reached the code to upload the file. Increasing the timeout on lambda fixed my problem

这篇关于Python和CSV文件中的嵌套循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆