擅长:python、mysql、java
<p>我想至少有一些人看到这个问题会像我一样,希望有一种方法从boto逐行(或逗号,逗号,或任何其他分隔符)流文件。有一个简单的方法:</p>
<pre><code>def getS3ResultsAsIterator(self, aws_access_info, key, prefix):
s3_conn = S3Connection(**aws_access)
bucket_obj = s3_conn.get_bucket(key)
# go through the list of files in the key
for f in bucket_obj.list(prefix=prefix):
unfinished_line = ''
for byte in f:
byte = unfinished_line + byte
#split on whatever, or use a regex with re.split()
lines = byte.split('\n')
unfinished_line = lines.pop()
for line in lines:
yield line
</code></pre>
<p>@garnaat上面的回答仍然很好,100%正确。希望我的还是能帮助别人。</p>