【发布时间】:2020-02-05 12:34:36
【问题描述】:
我有 2 个 python 程序,即 a1.py、a2.py
我想在 a2.py 中导入 a1.py。
以下是示例代码: a1.py:
class a:
def __init__(self):
#code
def __str__(self):
#code
def f1(self):
#code
def f2(self,file):
#code to read a file
and call f1 to do operations
#returns final text as str
m = a()
m.f2("file")
a2.py
class b:
def __init__(self):
#code
def __str__(self)
#code
def f3(self,text) #this text is the output of a1.py
#code
def f4(self)
#code gives the final output as list and calls f3
n = b()
n.f4()
如何在 a2.py 中使用 a1.py 的输出?
【问题讨论】:
-
如果您包含 Python 代码,请确保缩进正确;原样的代码不会运行。
-
您的
a1.py和a2.py无效modules,请阅读:if __name__ == "__main__":和 Python - Object Oriented
标签: python python-3.x oop