@@ -60,53 +60,53 @@ include:
6060Modules
6161-------
6262
63- Python modules are one of the main abstraction layer available and probably the
63+ Python modules are one of the main abstraction layers available and probably the
6464most natural one. Abstraction layers allow separating code into parts holding
65- related data and functionalities .
65+ related data and functionality .
6666
6767For example, a layer of a project can handle interfacing with user actions,
6868while another would handle low-level manipulation of data. The most natural way
69- to separate these two layers is to regroup all interfacing functionalities
69+ to separate these two layers is to regroup all interfacing functionality
7070in one file, and all low-level operations in another file. In this case,
71- the interface file need to import the low-level file. This is done with the
71+ the interface file needs to import the low-level file. This is done with the
7272`import ` and `from ... import ` statements.
7373
74- As soon as you use `import ` statements you use modules, either builtin modules
75- such as `os ` and `sys `, or third-party modules you have installed in your
76- environment, or project's internal modules.
74+ As soon as you use `import ` statements you use modules. These can be either built-in
75+ modules such as `os ` and `sys `, third-party modules you have installed in your
76+ environment, or your project's internal modules.
7777
7878Nothing special is required for a Python file to be a module, but the import
79- mechanism need to be understood in order to use this concept properly and avoid
79+ mechanism needs to be understood in order to use this concept properly and avoid
8080some issues.
8181
8282Concretely, the `import modu ` statement will look for the proper file, which is
8383`modu.py ` in the same directory as the caller if it exists. If it is not
84- found, the Python interpreter with search for `modu.py ` in the "path"
84+ found, the Python interpreter will search for `modu.py ` in the "path"
8585recursively and raise an ImportError exception if it is not found.
8686
8787Once `modu.py ` is found, the Python interpreter will execute the module in an
8888isolated scope. Any top-level statement in `modu.py ` will be executed,
89- including other imports if any. Function and classes definitions are stored in
89+ including other imports if any. Function and class definitions are stored in
9090the module's dictionary.
9191
92- Then modules variables, functions and classes will be available to the caller
92+ Then, the module's variables, functions, and classes will be available to the caller
9393through the module's namespace, a central concept in programming that is
9494particularly helpful and powerful in Python.
9595
96- In many languages, a `include file ` directive is used by the preprocessor to
97- take all code found in the file and 'copy' it in the caller's code. It is
96+ In many languages, an `include file ` directive is used by the preprocessor to
97+ take all code found in the file and 'copy' it into the caller's code. It is
9898different in Python: the included code is isolated in a module namespace, which
9999means that you generally don't have to worry that the included code could have
100- unwanted effect, eg override an existing function with the same name.
100+ unwanted effects, e.g. override an existing function with the same name.
101101
102102It is possible to simulate the more standard behavior by using a special syntax
103103of the import statement: `from modu import * `. This is generally considered bad
104- practice, **using import * makes code harder to read and dependencies less
105- compartimented **.
104+ practice. **Using ` import *` makes code harder to read and makes dependencies less
105+ compartmentalized **.
106106
107107Using `from modu import func ` is a way to pinpoint the function you want to
108- import and put it is the global namespace. While much less harmful than `import
109- * ` because it shows explicitely what is imported in the global namespace, it's
108+ import and put it in the global namespace. While much less harmful than `import
109+ * ` because it shows explicitly what is imported in the global namespace, its
110110advantage over a simpler `import modu ` is only that it will save some typing.
111111
112112**Very bad **
@@ -134,13 +134,13 @@ advantage over a simpler `import modu` is only that it will save some typing.
134134 [... ]
135135 x = modu.sqrt(4 ) # sqrt is visibly part of modu's namespace
136136
137- As said in the section about style, readability is one of the main feature of
137+ As said in the section about style, readability is one of the main features of
138138Python. Readability means to avoid useless boilerplate text and clutter,
139139therefore some efforts are spent trying to achieve a certain level of brevity.
140- But terseness and obscurity are the limits where brevity should stop: being
141- able to tell immediately from where comes a class or a function, as in the
142- `modu.func ` idiom, improves greatly code readability and understandability in
143- most cases but the simplest single file projects.
140+ But terseness and obscurity are the limits where brevity should stop. Being
141+ able to tell immediately where a class or function comes from , as in the
142+ `modu.func ` idiom, greatly improves code readability and understandability in
143+ all but the simplest single file projects.
144144
145145
146146Packages
0 commit comments