0

I want to pass the "ref" variable while running the old.py in my python script. How can I do it?

ref = true
os.system('old.py -setting + ref') ???? (its not correct)

what is best way to pass the ref variable while running old.py inside main python script?

Thanks.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Does this answer your question? [What is the best way to call a script from another script?](https://stackoverflow.com/questions/1186789/what-is-the-best-way-to-call-a-script-from-another-script) – Tomerikoo Dec 15 '20 at 22:08

3 Answers3

3

Don't use os.system; use subprocess instead.

import subprocess


ref = "true"
subprocess.run(["old.py", "-setting", ref])

If ref really is a Boolean-valued variable, you'll have to convert it to a string first.

import subprocess


ref = True
subprocess.run(["old.py", "-setting", str(ref).lower()])
chepner
  • 497,756
  • 71
  • 530
  • 681
3

How about the following code?

import os

ref = 'true'
os.system('python old.py -setting ' + ref)

It should run the following command in the operating system.

python old.py -setting true
modnar
  • 274
  • 1
  • 6
0

Use string formatting or concatenation.

ref = 'true'
os.system(f'old.py -setting {ref}')
Barmar
  • 741,623
  • 53
  • 500
  • 612