Skip to content

Commit b7bc8f1

Browse files
CooCoo
Coo
authored and
Coo
committed
10.7小节完成
1 parent fe7eb35 commit b7bc8f1

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

source/c10/p07_make_directory_or_zip_runnable_as_main_script.rst

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
----------
66
问题
77
----------
8-
You have a program that has grown beyond a simple script into an application involving
9-
multiple files. You’d like to have some easy way for users to run the program.
8+
您有已经一个复杂的脚本到涉及多个文件的应用程序。你想有一些简单的方法让用户运行程序。
109

1110
|
1211
1312
----------
1413
解决方案
1514
----------
16-
If your application program has grown into multiple files, you can put it into its own
17-
directory and add a __main__.py file. For example, you can create a directory like this:
15+
如果你的应用程序已经有多个文件,你可以把你的应用程序放进它自己的目录并添加一个__main__.py文件。 举个例子,你可以像这样创建目录:
1816

1917
.. code-block:: python
2018
@@ -24,16 +22,15 @@ directory and add a __main__.py file. For example, you can create a directory li
2422
grok.py
2523
__main__.py
2624
27-
If __main__.py is present, you can simply run the Python interpreter on the top-level
28-
directory like this:
25+
如果__main__.py存在,你可以简单地在顶级目录运行Python解释器:
2926

3027
.. code-block:: python
3128
3229
bash % python3 myapplication
3330
34-
The interpreter will execute the __main__.py file as the main program.
31+
解释器将执行__main__.py文件作为主程序。
3532

36-
This technique also works if you package all of your code up into a zip file. For example:
33+
如果你将你的代码打包成zip文件,这种技术同样也适用,举个例子:
3734

3835
.. code-block:: python
3936
@@ -48,15 +45,11 @@ This technique also works if you package all of your code up into a zip file. Fo
4845
----------
4946
讨论
5047
----------
51-
Creating a directory or zip file and adding a __main__.py file is one possible way to
52-
package a larger Python application. It’s a little bit different than a package in that the
53-
code isn’t meant to be used as a standard library module that’s installed into the Python
54-
library. Instead, it’s just this bundle of code that you want to hand someone to execute.
48+
创建一个目录或zip文件并添加__main__.py文件来将一个更大的Python应用打包是可行的。这和作为标准库被安装到Python库的代码包是有一点区别的。相反,这只是让别人执行的代码包。
5549

5650

57-
Since directories and zip files are a little different than normal files, you may also want
58-
to add a supporting shell script to make execution easier. For example, if the code was
59-
in a file named myapp.zip, you could make a top-level script like this:
51+
由于目录和zip文件与正常文件有一点不同,你可能还需要增加一个shell脚本,使执行更加容易。例如,如果代码文件名为myapp.zip,你可以创建这样一个顶级脚本:
52+
6053

6154
.. code-block:: bash
6255

0 commit comments

Comments
 (0)