【问题标题】:Access same class with written data across multiple files使用跨多个文件的写入数据访问同一类
【发布时间】:2022-08-17 23:50:13
【问题描述】:

我的示例代码

# file1.py
global Internal

class Internal:
    ...

# file2.py
import file1

myobject.Internal = Internal(do_stuff=\"foo\")
# file3.py
import file1

print(Internal.do_stuff)
>> foo

我该如何进行这项工作? 我需要我的代码随时将变量写入类并随时读取并在整个项目的运行时工作。

    标签: python


    【解决方案1】:

    file3 对 file2 中发生的事情一无所知

    您应该在 file3 中添加的是:

    from file2 import *
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多