-1

so have 2 python project file one is qr scanner and other is youtube downloader. adn both are in different python file

so i wanna create an main python file where i will list the both project name like:

  1. Qr Scanner
  2. YouTube Downloader Enter You Option:

So when the user input their option. the script will gonna run in background using another terminal...

i searched in internet i dont understand anything so i didnt tried anything else

i dont know how to do it and where to start it

  • You'd have to start by sharing any code to get any relevant answer, but it sounds like you just need to import both of those modules and call there main entry points. – theherk May 10 '22 at 18:44
  • i want to run all my script from an main.py file..... i dont know how to start it so i didnt do any coding – md Joynal Abedin May 11 '22 at 04:59
  • I think you'll want to start with [Imports](https://docs.python.org/3/reference/import.html) and [Modules](https://docs.python.org/3/tutorial/modules.html). Using subprocess for this is not good idea. Not that it is unsafe in this case, but it spawns more processes than necessary. If you want to create a python module that uses two other python modules / packages you just import them and call their api's directly. – theherk May 11 '22 at 06:31
  • Here is a great answer on this topic. [How can I import other python files](https://stackoverflow.com/a/20749411/2081835) – theherk May 11 '22 at 06:32
  • i also want to see the code running on the background terminal....how to do it? – md Joynal Abedin May 11 '22 at 06:52
  • Just output from your python application. As soon as it starts running, you have access to stdout and stderr from your program, anything you output will go there. – theherk May 11 '22 at 07:37

1 Answers1

1

It sounds like subprocess is what you want. It allows you to make command line calls by passing arguments to .run() method.

For example, you can call the ls bash command to get a list of files in the current directory.

import subprocess as sp
out = sp.run("ls", capture_output=True)
print(out.sdtout)
Sean
  • 524
  • 2
  • 7
  • can i use it to run my external project file from another python file? – md Joynal Abedin May 11 '22 at 05:00
  • If you can call your python file form the terminal, then you can also call it with the subprocess module. Something along the lines of sp.run("python my_file.py", capture_output=True). You'll can check the documentation to see how to pass cmd line arguments as well. – Sean May 11 '22 at 21:18