How to return data from one python file to another

2019-09-01 07:51发布

I am using a python file. I want to call another python code. Is there any way by which i can return data from 2nd python code to calling python code. Anything like function returns value to calling function.

2条回答
冷血范
2楼-- · 2019-09-01 08:01

Get everything into classes and functions and read a lot about importing modules

查看更多
做自己的国王
3楼-- · 2019-09-01 08:18

I must admit I don't see the problem:

test1.py:

def myfunc():
    return "spam!"

test2.py:

import test1
print(test1.myfunc())

Output when running test2.py:

spam!
查看更多
登录 后发表回答