如何使批处理文件运行python应用程序

时间:2021-10-17 02:32:02

I have a folder named app which consists of few py files.

我有一个名为app的文件夹,其中包含几个py文件。

Folder App
   - a.py
   - b.py
   - c.py
   - main.py

I have to run main.py file to run this application which is linked with other files.

我必须运行main.py文件来运行与其他文件链接的此应用程序。

My question is can i create a batch file to run this application

我的问题是我可以创建一个批处理文件来运行这个应用程序

1 个解决方案

#1


1  

Inside main.py you can import all the files which it requires.
Python 3

在main.py中,您可以导入它需要的所有文件。 Python 3

from .a import *
from .b import *

This will import everything in a.py and b.py in main.py

这将导入main.py中的a.py和b.py中的所有内容

If you really want to make a batch script, you can just write following in a file with .bat extension, say controller.bat:

如果你真的想制作一个批处理脚本,你可以在扩展名为.bat的文件中写下来,比如controller.bat:

If controller.bat is in same directory:

如果controller.bat在同一目录中:

python3 main.py

If controller.bat is in some different directory, then you will need to give full path to main.py, something like this:

如果controller.bat在某个不同的目录中,那么你需要提供main.py的完整路径,如下所示:

python3 "D://mydrive/pythonCodes/apps/main.py"

#1


1  

Inside main.py you can import all the files which it requires.
Python 3

在main.py中,您可以导入它需要的所有文件。 Python 3

from .a import *
from .b import *

This will import everything in a.py and b.py in main.py

这将导入main.py中的a.py和b.py中的所有内容

If you really want to make a batch script, you can just write following in a file with .bat extension, say controller.bat:

如果你真的想制作一个批处理脚本,你可以在扩展名为.bat的文件中写下来,比如controller.bat:

If controller.bat is in same directory:

如果controller.bat在同一目录中:

python3 main.py

If controller.bat is in some different directory, then you will need to give full path to main.py, something like this:

如果controller.bat在某个不同的目录中,那么你需要提供main.py的完整路径,如下所示:

python3 "D://mydrive/pythonCodes/apps/main.py"