如何将数据从一个python文件返回到另一个python文件 [英] How to return data from one python file to another python file

查看:250
本文介绍了如何将数据从一个python文件返回到另一个python文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用python文件.我想调用另一个python代码.有什么办法可以让我从第二个python代码返回数据到调用python代码.任何类似函数的值都会返回给调用函数.

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.

推荐答案

我必须承认我没有看到问题:

I must admit I don't see the problem:

test1.py:

def myfunc():
    return "spam!"

test2.py:

import test1
print(test1.myfunc())

运行test2.py时的输出:

spam!

这篇关于如何将数据从一个python文件返回到另一个python文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆