0

im running the script2 from script 1, but i cant get the value from script2 after run

sc1.py

import sys import os import sc2 os.system ('python sc2.py') varB = sc2.main(varA) print(varB) 

sc2.py

def main(_argv): varA = 'Hello' if __name__ == '__main__': try: app.run(main) except SystemExit: pass 

sc1 didnt print anything, how to do it?

2
  • Can you explain what you are trying to do? Commented Feb 12, 2021 at 17:48
  • i need to get output from sc2 and print it or store it in sc1 Commented Feb 12, 2021 at 17:57

2 Answers 2

1

Your function in sc2 is not returning anything. So you are not getting any output in sc1. include a return statement in main.

Sign up to request clarification or add additional context in comments.

1 Comment

im using return in sc2 still not print anything from sc1
1

sc1.py

import sys import os import sc2 os.system ('python sc2.py') varB = sc2.main("Hello") #sc1 doesn't know varA print(varB) 

sc2.py

def main(_argv): varA = _argv return varA # in order to actually return varA if __name__ == '__main__': try: app.run(main) except SystemExit: pass 

Two points:

  • You can't use varA in sc1.py, because sc1.py doesn't know it. It's defined in sc2.py
  • You have to literally use the keyword return and whatever you want to return so that that value will be returned by sc2.py's main function and stored in varB.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.