使用循环外的列表将url字符串与某些列表值连接起来

2024-04-27 19:36:34 发布

您现在位置:Python中文网/ 问答频道 /正文

Im正在从sqs队列获取3条消息:映射器.py, 减速器.py以及测试.txt …我把每一条信息都存储在一个列表中。在

我想在我的mapper、reducer和输入变量(最后3行代码)中使用每条消息的内容。在

但是在while循环之外,我有print "Connecting to EMR"我不知道如何使用我的文件名列表达到我想要的目的。在

你有什么解决办法吗?在

在for循环中的print item中,它只显示filenames\u列表的第一个元素。在

conn = SQSConnection()
myqueue = conn.get_queue('myQueue')
while myqueue.count() != 0:
    filenames_list = list()
    message = myqueue.read()

    myqueue.delete_message(message)
    filename = message.get_body()

    filenames_list.append(filename)


for item in files_list: 
    print item

print "Connecting to EMR"
conn = boto.emr.connect_to_region('us-east-1')
print "Creating Streaming step"
step = StreamingStep(name='Example1',

# after myFolder/ I want to put here the content of my list relative to test.txt

mapper="s3n://myFolder/HereIWantToPutTheListContentRelatedToMapper.py",  

# after myFolder/ I want to put here the content of my list relative to reducer.py

reducer="s3n://myFolder/HereIWantToPutTheListContentRelatedToReducer.py",   

# after myFolder/ I want to put here the content of my list relative to mapper.py 
input='s3n://myFolder/HereIWantToPutTheListContentRelatedToTest.txt',  

output='s3n://myFolder/output/wordcount_output')

Tags: topytxtmessage列表connitemlist
1条回答
网友
1楼 · 发布于 2024-04-27 19:36:34

在while\u循环的每次迭代开始时,您都要将files\u list初始化为空列表,所以您可能希望在列表之外初始化它,并在while循环的每次迭代时将其附加到该列表中?在

相关问题 更多 >