我从sqs队列获得3条消息:mapper.py,reducer.py和test.txt ...并且我将每条消息存储在列表中。
我想在mapper,reducer和输入变量(最后3个代码行)中使用每条消息的内容。
但是在我的while循环之外我已经print "Connecting to EMR"
我没有看到如何将我的文件名列表用于我想要的目的。
你看到了解决方案吗?
在我的print item
里面for循环中,它只显示了filenames_list的第一个元素。
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')
答案 0 :(得分:2)
你是在while_loop的每次迭代开始时将files_list初始化为一个空列表,所以也许你想在列表之外初始化它并在while循环的每次迭代中追加它?