Search code examples
pythonpython-3.xinterprocess

Can I access a list from another running python script


If I have two scripts, one has a list and is currently running and the other one needs to access that list while the first one is running, how would I do that?

Example

Script 1

import random
example_list = []
while True:
    example_list.append(random.randint(0,9))

Script 2

x = example_list[i]

I can not change Script 1.
How would I access the list created in Script 1 from Script 2?

P.S. This is just an example so it's purpose doesn't matter.


Solution

  • No! You can not do it. At least in python.

    There is no way you can access a variable in another running process.