readline() method is giving error: AttributeError: 'tuple' object has no attribute 'readline'

readline() method is giving error: AttributeError: 'tuple' object has no attribute 'readline'

我正在使用 jsonstreams.Stream 方法使用 Python 2.7 将数据输入到 json 文件中,但是在尝试使用 readline 从 PIPE 输入读取数据时出现错误() 方法。错误指出 A​​ttributeError: 'tuple' object has no attribute 'readline'.

branch_name = 'man/ashish_c/robotics'
days = '60'
json_output = 'output_log.json'

proc = subprocess.Popen(['git', 'log', branch_name, '--since="60 days ago"', '--pretty=%p\t%h\t%an\t%s\t%b'], shell=True, stdout=subprocess.PIPE)
stdout_value = proc.communicate()

with jsonstreams.Stream(jsonstreams.Type.array, filename=json_output) as output:
    while True:
        line = stdout_value.readline()
        if not line:
            break
        record = line.decode("utf-8").split("\t")
        with output.subobject() as output_e:
            output_e.write('merge', record[0])
            output_e.write('commit', record[1])
            output_e.write('author', record[2])
            output_e.write('title', record[3])
            output_e.write('body', record[4])

我希望 output_log.json 的内容看起来像这样:

[
    {"commit": "3011203d", "merge": "e84d9feb", "author": "me", "title": "test commit", "body": "..."},
    {"commit": "5033203d", "merge": "u67d9feb", "author": "Dmitri", "title": "check infra", "body": ".."}
    .....
]

Popen.communicate() returns (stdout_data, stderr_data) 的元组。参见 https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate

假设您想从 stdout_data 中读取,请尝试替换行

stdout_value = proc.communicate()

stdout_value, stderr_value = proc.communicate()