-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* merge 6e7639a π° * [6e7639a] λ²μ * [6e7639a] build
- Loading branch information
Showing
16 changed files
with
552 additions
and
724 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 26 additions & 11 deletions
37
Google Python Style Guide/2. Python μΈμ΄ κ·μΉ/2.20 νλμ νμ΄μ¬.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,61 @@ | ||
<a id="s2.20-modern-python"></a> | ||
|
||
### 2.20 Modern Python : Python 3 κ·Έλ¦¬κ³ from, \_\_future\_\_, imports | ||
### 2.20 Modern Python : from, \_\_future\_\_, imports | ||
|
||
- Python 3 λ²μ μ΄ λμμ΅λλ€! μμ§ νλ‘μ νΈμ Python 3μ μ¬μ©ν μ€λΉκ° λμ΄μλ 건 μλμ§λ§ λͺ¨λ μ½λλ νΈνλλλ‘ μμ±λμ΄μΌ ν©λλ€. (κ°λ₯ν κ²½μ°μ Python 3μ λ°λΌ ν μ€νΈν©λλ€.) | ||
- μλ‘μ΄ μΈμ΄ λ²μ μλ―Έ μ²΄κ³ λ³κ²½ μ¬νμ μ΄μ λ°νμ λ΄μμ νμΌ λ¨μλ‘ νμ±ννκΈ° μν΄ νΉλ³ν ν₯ν κ°μ Έμ€κΈ° λ€μ μ μ΄λ μ μμ΅λλ€. | ||
(New language version semantic changes may be gated behind a special future import to enable them on a per-file basis within earlier runtimes.) | ||
|
||
<a id="s2.20.1-definition"></a> | ||
|
||
#### 2.20.1 μ μ | ||
|
||
- Python 3λ PythonμΈμ΄μμ μ€μν λ³νκ° μμ΅λλ€. νμ¬ μ¬μ©νκ³ μλ μ½λλ 2.7 λ²μ μ μΌλνμ¬ μμ±νλ κ²½μ°κ° λ§μ΅λλ€. | ||
- Python3μμ μμ μμ΄ μ¬μ©ν μ μλλ‘ μ μ€λΉνκΈ° μν΄μ μ½λμ μλλ₯Ό λͺ ννκ² λ§λ€ μ μκ² νλ λͺλͺ κ°λ¨ν κ²λ€μ΄ μμ΅λλ€. | ||
- `from __future__ import`λ¬Έμ ν΅ν΄ λ³΄λ€ νλμ μΈ κΈ°λ₯ μ€ μΌλΆλ₯Ό νμ±νν μ μμΌλ©΄ μμλλ ν₯ν Python λ²μ μ κΈ°λ₯μ μ‘°κΈ°μ μ¬μ©ν μ μμ΅λλ€. | ||
|
||
<a id="s2.20.2-pros"></a> | ||
|
||
#### 2.20.2 μ₯μ | ||
|
||
- Python 3λ₯Ό μΌλν΄ λκ³ μμ±λ μ½λλ λͺ ννκ³ νλ‘μ νΈμ λͺ¨λ μμ‘΄μ±μ΄ Python 3μμ μ€ννκΈ°κ° λ μ¬μμ§λλ€. | ||
- μ΄λ νΈνμ±μ μ μΈνκ³ ν΄λΉ νμΌ λ΄μμ νκ·λ₯Ό λ°©μ§νλ©΄μ νμΌλ³λ‘ λ³κ²½μ΄ μ΄λ£¨μ΄μ§ μ μμΌλ―λ‘ λ°νμ λ²μ μ κ·Έλ μ΄λλ₯Ό λ μννκ² λ§λλ κ²μΌλ‘ μ μ€λμμ΅λλ€. | ||
- μ΅μ μ½λλ ν₯ν λ°νμ μ κ·Έλ μ΄λ μ€μ λ¬Έμ κ° λ μ μλ κΈ°μ μ λΆμ±κ° μΆμ λ κ°λ₯μ±μ΄ μ κΈ° λλ¬Έμ μ μ§ κ΄λ¦¬κ° λ μ½μ΅λλ€. | ||
|
||
<a id="s2.20.3-cons"></a> | ||
|
||
#### 2.20.3 λ¨μ | ||
|
||
- μ΄λ€ μ¬λλ€μ μΆκ°λ boilerplateκ° μΆνλ€κ³ μκ°ν©λλ€. μ¬μ©νμ§ μλ κΈ°λ₯μ importνλ κ²μ μ΄λ‘μ μ λλ€. | ||
- μ΄λ¬ν μ½λλ νμν feature λ¬Έμ λμ νκΈ° μ μλ λ§€μ° μ€λλ μΈν°νλ¦¬ν° λ²μ μμ λμνμ§ μμ μ μμ΅λλ€. | ||
- μΌλ°μ μΌλ‘ λ€μν νκ²½μ μ§μν΄μΌνλ νλ‘μ νΈμμ νμν©λλ€. | ||
|
||
<a id="s2.20.4-decision"></a> | ||
|
||
#### 2.20.4 κ²°λ‘ | ||
|
||
##### from \_\_future\_\_ imports | ||
|
||
- `from __future__ import` ννλ₯Ό μ¬μ©νλ κ²μ΄ λ°λμ§ν©λλ€. λͺ¨λ μλ‘μ΄ μ½λλ λ€μ μ¬νμ΄ ν¬ν¨λμ΄μΌ νλ©° κ°λ₯ν κ²½μ° κΈ°μ‘΄ μ½λκ° νΈνλλλ‘ μ λ°μ΄νΈ ν΄μΌ ν©λλ€ | ||
- `from __future__ import`λ¬Έμ μ¬μ©νλ κ²μ΄ μ’μ΅λλ€. | ||
- μ£Όμ΄μ§ μμ€νμΌμμ λμ± νλμ μΈ Python ꡬ문 κΈ°λ₯μ μ¬μ©ν μ μμ΅λλ€. | ||
- `__future__` import λ€μ κΈ°λ₯μ΄ μ¨κ²¨μ Έ μλ λ²μ μμ λ μ΄μ μ€νν νμκ° μλ€λ©΄ ν΄λΉ μ€μ μμ λ‘κ² μ κ±°νμΈμ. | ||
- 3.7 μ΄μμ΄ μλ 3.5 μ΄μ λ²μ μμ μ€νλ μ μλ μ½λμμ κ°μ Έμ¬ κ²½μ° | ||
|
||
```python | ||
from __future__ import generator_stop | ||
``` | ||
|
||
- 2.7 λ²μ μ κ³μ μ§μν΄μΌνλ λΆλ΄μ΄ μλ λ κ±°μ μ½λμ κ²½μ° | ||
|
||
```python | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
``` | ||
|
||
- `import`μ λν μμΈν λ΄μ©μ [absolute imports](https://www.python.org/dev/peps/pep-0328/), [`/` division behavior](https://www.python.org/dev/peps/pep-0238/), [the `print` function](https://www.python.org/dev/peps/pep-3105/)μ μ°Έμ‘°νμΈμ. | ||
- μ΄λ¬ν importλ νμ¬ λͺ¨λμμ μ¬μ©λμ§ μλλΌλ μλ΅νκ±°λ μ κ±°νμ§ λ§μΈμ. λͺ¨λ νμΌμ νμ ν₯ν importκ° μμΌλ―λ‘ λμ€μ μ΄λ¬ν κΈ°λ₯μ μ¬μ©νκΈ° μμν λ νΈμ§νλ λμ μμ§ μλλ‘ νλ κ²μ΄ μ’μ΅λλ€. | ||
- λ€λ₯Έ `from __future__` import λͺ μΈλ μμΌλ μλ§κ² μ¬μ©νμΈμ. `unicode_literals`λ νμ΄μ¬ 2.7 λ΄ μ¬λ¬ κ³³μμ λμ λλ μ묡μ κΈ°λ³Έ μ½λ± λ³ν κ²°κ³Ό λλ¬Έμ λͺ ννμ§ μκΈ° λλ¬Έμ κΆκ³ μ¬νμ ν¬ν¨μν€μ§ μμμ΅λλ€. λλΆλΆμ μ½λλ νμμ λ°λΌ `b''`, `u''` λ°μ΄νΈλ₯Ό λͺ μμ μΌλ‘ μ¬μ©νκ³ μ λμ½λ λ¬Έμμ΄ literalλ₯Ό μ¬μ©νλ©΄ λ μ’μ΅λλ€. | ||
- μμΈν λ΄μ©μ [Python future statement definitions](https://docs.python.org/3/library/__future__.html) λ¬Έμλ₯Ό μ½μ΄λ³΄μΈμ. | ||
- μ½λκ° μΆ©λΆν νλμ μΈ νκ²½μμλ§ μ¬μ©λλ€λ νμ μ΄ λ€ λκΉμ§ μ΄λ¬ν importλ₯Ό μ κ±°νμ§ λ§μΈμ. | ||
- νμ¬ μ½λμμ νΉμ ν₯ν importλ₯Ό ν΅ν΄ νμ±νλλ κΈ°λ₯μ νμ¬ μ¬μ©νμ§ μλλΌλ νμΌμ ν΄λΉ κΈ°λ₯μ μ μ§νλ©΄ λμ€μ μ½λκ° μ΄μ λμμ λ°λΌ μ€μλ‘ μμ λλ κ²μ λ°©μ§ν μ μμ΅λλ€. | ||
- μ μ νλ€κ³ μκ°λλ λ€λ₯Έ `from __future__` import λ¬Έμ μ¬μ©νμΈμ. | ||
- 2.7λ²μ λ΄μ μ¬λ¬ μμΉμμ λμ λ μμμ κΈ°λ³Έ μ½λ± λ³ν κ²°κ³Όλ‘ μΈν΄ νμ€νμ§ μμκΈ° λλ¬Έμ 2.7λ²μ μ λν κΆμ₯ μ¬νμ `unicode_literals`λ₯Ό ν¬ν¨νμ§ μμμ΅λλ€. | ||
- λλΆλΆμ μ΄μ€ λ²μ 2-3 μ½λλ νμν κ²½μ° `b''` μ `u''` qλ°νΈμ μ λμ½λ λ¬Έμμ΄ λ¦¬ν°λ΄μ λͺ μμ μΌλ‘ μ¬μ©νλ κ²μ΄ λ λμμ΅λλ€. | ||
|
||
##### six, future κ·Έλ¦¬κ³ past λΌμ΄λΈλ¬λ¦¬ | ||
|
||
- νλ‘μ νΈκ° Python 2, 3 λͺ¨λ μ§μν΄μΌνλ κ²½μ°μ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ ν©νκ² μ¬μ©νλ κ²μ κΆμ₯ν©λλ€. μ½λλ₯Ό λ κΉ¨λνκ³ μΆμ λ μ½κ² λ§λ€κΈ° μν΄ μ‘΄μ¬ν©λλ€. | ||
- νλ‘μ νΈκ° μ¬μ ν Python 2, 3 λͺ¨λμμ μ¬μ©μ μ§μν΄μΌνλ κ²½μ° μ ν©νλ€κ³ νλ¨λλ λλ‘ [six](https://pypi.org/project/six/), [future](https://pypi.org/project/future/), λ° [past](https://pypi.org/project/past/) λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©νμΈμ. | ||
- μ½λλ₯Ό λ κΉ¨λνκ³ μΆμ λ μ½κ² λ§λ€κΈ° μν΄ μ‘΄μ¬ν©λλ€. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.