我有下面的代码,
def hello(start, end):
perform some function
for i in range(j):
yield (some value)
yield (some value)
def calc(start, end):
start = "x"
end = "y"
for d in hello(start, end):
perform some function
data = 123
perform some function
data1 = 456
return data, data1
def world(hello()):
with open(r"C:filepathabc.json",'w') as file:
json.dump(hello.data, file)
with open(r"C:filepathabc.json") as file1:
d = json.load(file1)
return d
- 现在,我想使用hello((函数的返回值(data&data1(在world((函数中,还希望使用来自world(函数在另一个函数中
- 此外,world((函数将作为模块导入,并且应该在另一个模块的函数中使用
我该怎么做?
- 您可以使用
*
运算符来解包返回值。以下示例适用于我:
def func1():
return 10, 's10'
def func2(code, codeString):
print("code: ", code)
return codeString
cs = func2(*func1())
print("Code string: ", cs)
有关详细信息,请将元组作为函数参数。