0

Skript_2 will print "1" as sample is declared initialy. But I want to send sample after it was changed in Skript 1 (so it should print "2"). How can I do that?

# Skript_1
import os
sample = 1

def changeSample(s):
    global sample   
    sample = s + 1


if __name__ == '__main__':
    changeSample(sample)
    os.system('python Skript_2.py')

#Skript 2
from Skript_1 import sample
print(sample)
Pm740
  • 339
  • 2
  • 12
  • 1
    Does this answer your question? [Importing variables from another file?](https://stackoverflow.com/questions/17255737/importing-variables-from-another-file) – bbnumber2 Oct 22 '20 at 14:30
  • Unfortunately not. This will get me all gobal variables and functions of the initial script. But I change those variables in the initial script while it is running. I want to use the changed variables in the second script. – Pm740 Oct 22 '20 at 14:35
  • 1
    `os.system('python Skript_2.py')` is starting a new instance of the program, which doesn't share memory or anything with your first script. To do what you're trying to do, you'd need to look into inter-process communication. – Carcigenicate Oct 22 '20 at 14:37
  • Thank you for your response. I assumed that. Because inter-process communication is a pretty lagre topic I thought someone more adpt than me could give me a hint. :) – Pm740 Oct 22 '20 at 15:06

0 Answers0