【问题标题】:Python - How to invoke another .py file and use its return valuePython - 如何调用另一个 .py 文件并使用它的返回值
【发布时间】:2018-08-31 18:32:33
【问题描述】:

如何在另一个文件中使用返回值?

File1:
    def system(self):
        # do something
        return: value_1, value_2

File2:
    def to_do(self):
       # do something
       result = file_location.file1(value_1, value2)

这是正确的方法吗?

【问题讨论】:

标签: python subprocess return-value


【解决方案1】:

您应该在File2.py中导入您要使用的File1.py的具体方法。 另请注意,python 可以返回多个值以及我如何将它们存储在 File2.py 中。

File1.py

    def system(self):
        # do something
        return value_1, value_2

文件2.py

    from File1 import system
    def to_do(self):
       # do something
       result1, result2 = system(value_1, value2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 2011-09-29
    相关资源
    最近更新 更多