Skip to content

Instantly share code, notes, and snippets.

@kasimte
Created February 2, 2021 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kasimte/e420538fca82c25cbb53fb9f52a251af to your computer and use it in GitHub Desktop.
Save kasimte/e420538fca82c25cbb53fb9f52a251af to your computer and use it in GitHub Desktop.
Demo of running separate python script as subprocess and capturing output.
# output.py (separate file)
print(37.234)
# capture_output_from_script.py
import subprocess
# run output.py as subprocess and capture output, format it, convert to float, and print
x = float(subprocess.check_output('python output.py', shell=True, text=True).strip())
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment