Consider the following program, which is saved in a file named script.py
:
x = 2/3
x
(This is a script in Python, but actually my real script is in R -- I am using this Python script just for illustration of what I am wanting.)
Now, I want to use a second program in Python to get the numerical value of variable x
calculated in script.py
.
The following program accomplishes that but only partially, in the sense that the number with all decimal digits is not returned. In truth, float(s)
does not have the same decimal precision as x
.
import subprocess
cmd_line = ["python", "script.py"]
s = subprocess.check_output(cmd_line, text=True)
float(s)
What I want to obtain is the value of x
with the same precision as it gets in script.py
.
EDIT
This question was closed because -- it is argued -- it is a duplicate of previous question. I am not looking for a way to get arbitrary decimal precision: I am looking for a way to pass a numerical result of a Python script to a second Python script.
Please, I kindly and respectfully ask you for reopening the question.