1

I have the below code,

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:\filepath\abc.json",'w') as file:
        json.dump(hello.data, file)
    
    with open(r"C:\filepath\abc.json") as file1:
        d = json.load(file1)
    return d
  1. Now, I want to use return values(data & data1) from hello() function in world() function, also want to use return values from world() function in another function.
  2. Also, the world() function will be imported as a module and should be used in function in another module.

How could I do that?

1 Answers1

2
  1. You could use the * operator to unpack the return value. The following example works for me:
def func1():
    return 10, 's10'

def func2(code, codeString):
    print("code: ", code)
    return codeString
   

cs = func2(*func1())
print("Code string: ", cs)

Please see tuples as function arguments for more details.

hagh
  • 507
  • 5
  • 13