Advertisement
calfred2808

Python: Get value from another script

Aug 26th, 2022
1,026
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. '''
  2. https://stackoverflow.com/questions/30664263/return-value-from-one-python-script-to-another
  3. '''
  4.  
  5.  
  6. '''
  7. pass an argument to another script
  8. retrieve an output from another script to original caller
  9. '''
  10.  
  11.  
  12. #######################################
  13.  
  14.  
  15. #Script 1
  16. import sys
  17. import subprocess
  18. s2_out = subprocess.check_output([sys.executable, "script2.py", "34"])
  19. print(s2_out)
  20.  
  21.  
  22.  
  23. #####################################
  24.  
  25.  
  26. #script 2
  27.  
  28. import sys
  29. def main(arg):
  30.     print("Hello World"+arg)
  31.  
  32. if __name__ == "__main__":
  33.     main(sys.argv[1])
  34.  
  35.  
  36.  
Tags: python
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement