How to run a Python script from another Python script?

How to make so that from one script to run another Python, with parameters(a=1 for example) and the script continued and after the second closed
I can't find how to do it?
Python 3.7
March 19th 20 at 08:31
2 answers
March 19th 20 at 08:33
Solution
subprocess.Popen([sys.executable, 'script'], pair,m)
ie like this: subprocess.Popen([sys.executable 'ryn.py'], tel,colvo) - Scotty_Zie commented on March 19th 20 at 08:36
to import what we need import tipo..... - Scotty_Zie commented on March 19th 20 at 08:39
@Scotty_Zie, import subprocess - Marlene_Hand commented on March 19th 20 at 08:42
@Marlene_Hand, subprocess.Popen([sys.executable 'config.py'],a,b)
NameError: name 'sys' is not defined
error( - Scotty_Zie commented on March 19th 20 at 08:45
@Scotty_Zie, import sys - Marlene_Hand commented on March 19th 20 at 08:48
March 19th 20 at 08:35
Solution
The module import subprocess

import subprocess

subprocess.Popen(['python3', 'script.py', 'argzzz1', 'argzzz2'])


UPD:
The path to the Python3 interpreter
import sys
>>> sys.executable
'/usr/bin/python3'


Read more here
Traceback (most recent call last):
File "tesst.py", line 4, in
subprocess.Popen(['python3"config.py'],a,b)
File "/usr/local/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1413, in _execute_child
executable = os.fsencode(executable)
File "/usr/local/lib/python3.7/os.py", line 809, in fsencode
filename = fspath(filename) # Does the type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int
this error - Scotty_Zie commented on March 19th 20 at 08:38
@Scotty_Zie,
Comma
['python3', 'config.py'] - Breanna_Mitchell commented on March 19th 20 at 08:41
Traceback (most recent call last):
File "tesst.py", line 5, in
subprocess.Popen(['/usr/local/bin/python3.7','config.py'],a,b)
File "/usr/local/lib/python3.7/subprocess.py", line 756, in __init__
restore_signals, start_new_session)
File "/usr/local/lib/python3.7/subprocess.py", line 1413, in _execute_child
executable = os.fsencode(executable)
File "/usr/local/lib/python3.7/os.py", line 809, in fsencode
filename = fspath(filename) # Does the type-checking of `filename`.
TypeError: expected str, bytes or os.PathLike object, not int - Scotty_Zie commented on March 19th 20 at 08:44
@Scotty_Zie,

Just checked in the console
[8.2.0 GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> 
>>> subprocess.Popen(['python3', 'script.py', 'argzzz1', 'argzzz2'])
<subprocess.Popen object at 0x7f04274b7e10>
>>> ['script.py', 'argzzz1', 'argzzz2']
- Breanna_Mitchell commented on March 19th 20 at 08:47
what version of Python? - Scotty_Zie commented on March 19th 20 at 08:50
strangely, the console also starts and not in the file - Scotty_Zie commented on March 19th 20 at 08:53
how to make sure that there is variable a and b, and the second script needs them the amount, help - Scotty_Zie commented on March 19th 20 at 08:56
@Scotty_Zie, could put them in the ground and pass one argument
just pass it a string and not as int.

subprocess.Popen(['python3', 'script.py', '{0}'.format(7 + 3)])


and the second script converts the number to int(sys.argv[2]) - Breanna_Mitchell commented on March 19th 20 at 08:59
thanks, works) - Scotty_Zie commented on March 19th 20 at 09:02

Find more questions by tags Command linePython