我有这样的功能:如何修改这个函数来接受三个不同变量的返回?
import os
import subprocess
def find_remote_files(hostspec):
cmdline = ["rsync", "-e", "ssh", "-r", hostspec]
with open(os.devnull, "w") as devnull:
proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=devnull)
try:
for entry in proc.stdout:
items = entry.strip().split(None, 4)
if not items[0].startswith("d"):
yield items[4]
yield items[1]
yield items[2]
proc.wait()
except:
# On any exception, terminate process and re-raise exception.
proc.terminate()
proc.wait()
raise
这个函数返回三个不同的东西,我想存储在三个不同的变量,如:
a, b, c = find_remote_date('username', 'password')
# a should hold yield items[4]
# b should hold yield items[1]
# c should yield items[2]
我得到以下错误,当我尝试做即:
ValueError: too many values to unpack
你为什么认为'yield'比'return'好呢? –