简体   繁体   English

使 Python 脚本与正在运行的 Python 脚本交互

[英]Make a Python script interact with a running Python script

I have two Python scripts, a.py and b.py.我有两个 Python 脚本,a.py 和 b.py。 A.py is running and is not writable and I would like to have b.py being able to retrieve data from it, like a list of used variables and their values, functions, class... I am finding nothing on the Internet so is this possible ? A.py 正在运行且不可写,我希望 b.py 能够从中检索数据,例如使用的变量及其值、函数、类的列表......我在互联网上找不到任何东西这可能吗 ? Thanks.谢谢。

Example a.py示例 a.py

def numberOne(var):
    var1 = input('Enter a value : ')

class testClass():
    def __init__(self, value)
        self.var2 = value

var3 = 12345

Example b.py output示例 b.py 输出

Found class : 
-- testClass

Found functions :
-- numberOne

Found vars :
-- var3 : 12345

Might not be what you want but可能不是你想要的,但
You could try writing the data you need from a.py to c.py while a.py is running.您可以尝试在a.py运行时将您需要的数据从a.py写入c.py

f = open('text.txt', 'w')
f.write(what_you_want_to_write)

And then work with it in b.py .然后在b.py使用它。

There should be an IPC (inter-process communication) between a.py and b.py. a.py 和 b.py 之间应该有一个 IPC(进程间通信)。

In module a.py, you should have some line of codes getting all function, variable in a.py, then transmit these data to b.py via IPC.在模块 a.py 中,您应该有一些代码行获取 a.py 中的所有函数、变量,然后通过 IPC 将这些数据传输到 b.py。 Please refer to this link for getting the function list in a module.请参阅此链接以获取模块中的函数列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM