์ฝ๋ ๊ท์ฝ์ PEP8๊ณผ Google์ ์คํ์ผ ๊ฐ์ด๋๋ฅผ ์ต๋ํ ๋ฐ๋ฅธ๋ค. ์ ๊ฐ์ด๋์์ ์ค์ํ ๋ถ๋ถ์ด๋ ์ธ๊ธ๋์ง ์์ ๋ถ๋ถ ๊ทธ๋ฆฌ๊ณ ์๋ก ์์ถฉ๋๋ ๋ถ๋ถ์ ๋ฐ๋ก ์๋์ ๊ธฐ์ ํ๋ค.
-
๋ฆฌ์คํธ, ํํ, ๋์ ๋๋ฆฌ ์ฌ์ฉ์ ๋ง์ง๋ง์ ,(trailing commas)๋ฅผ ๋ถ์ธ๋ค.
- ๋ฐ์ดํฐ ์ถ๊ฐ์ diff ๋ณด๊ธฐ์ ํธํ๋ค.
-
Mixin์ผ๋ก ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ถ๋ชจ ํด๋์ค๋ฅผ ๊ฐ์ฅ ๋ง์ง๋ง์ ์ ๋๋ค.
- ex) Child(Mixin1, Mixin2, Parent)
-
๊ฐ๋ ์ฑ ๊ด๋ จ
-
๋ฐ๋ณต๋ฌธ๊ณผ ๋ถ๊ธฐ๋ฅผ ํ ๋ผ์ธ์ด ๊ฐ์ด ๋ด๋ ์์ ์ฝ๋๋ฅผ ์์ฑํ์ง ์๋๋ค.
# Bad content_ids = [content.id for content in contents if content is not None]
# Alternative content_ids = [content.id for content in filter(None, contents)] # or content_ids = map(lambda content: content.id, filter(None, contents))
-
- 1ํ์ 140์๊น์ง ์ฌ์ฉํ๋ค.
- ์ค๋ฐ๊ฟ, ๊ณต๋ฐฑ
-
ํจ์ ์ธ์ (์๋ ๋๋ค ๋๋ค)
foo = long_function_name( var_one, var_two, var_three, var_four ) print(var_one)
foo = long_function_name( var_one, var_two, var_three, var_four ) print(var_one)
-
- ์ธ๋ฏธ์ฝ๋ก ์ ์ฌ์ฉํ์ง ์๋๋ค.
- 2๊ฐ์ command ๋ฅผ ์ธ๋ฏธ์ฝ๋ก ์ ์ฌ์ฉํด ํ๋ผ์ธ์ ํํ์ด ๊ฐ๋ฅํ์ง๋ง ์ฌ์ฉํ์ง ์๋๋ค.
- ํด๋์ค
- ํด๋์ค์์ private ๋ฉค๋ฒ๋ ๋ฉ์๋๋ ์ด๋ฆ ์์ ๋ฐ์ค์ ์ถ๊ฐํ๋ค.
- ๋น๊ต
-
None
๊ณผ ๋น๊ต,Boolean
๋น๊ต๋is
,is not
์ ์ฌ์ฉํ๋ค. -Boolean
๋น๊ต:if not is_ok
: - ๊ฐ์ฒด์ ํ์ ์ ๋น๊ตํ ๋๋isinstance()
๋ฅผ ์ฌ์ฉํ๋ค. - ๋ฌธ์์ด
- string ๋ชจ๋๋ณด๋ค๋ string ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ค.
- ๋ฉ์๋๊ฐ ๋ชจ๋๋ณด๋ค ๋น ๋ฅด๊ณ ์ ๋์ฝ๋ ๋ฌธ์์ด์ ๋ํด ๊ฐ์ API ๋ฅผ ๊ณต์ ํ๋ค.
- ์ ๋์ฌ๋ ์ ๋ฏธ์ฌ๋ฅผ ๊ฒ์ฌํ ๋๋
startswith()
์endswith()
๋ฅผ ์ฌ์ฉํ๋ค.
- ๋ฉ์๋๊ฐ ๋ชจ๋๋ณด๋ค ๋น ๋ฅด๊ณ ์ ๋์ฝ๋ ๋ฌธ์์ด์ ๋ํด ๊ฐ์ API ๋ฅผ ๊ณต์ ํ๋ค.
- ์ ๋์ฌ๋ ์ ๋ฏธ์ฌ๋ฅผ ๊ฒ์ฌํ ๋๋
- string ๋ชจ๋๋ณด๋ค๋ string ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ค.
- ์ด๋ฆ๊ท์น
module_name
package_name
ClassName
method_name
ExceptionName
function_name
GLOBAL_CONSTANT_NAME
global_var_name
instance_var_name
function_parameter_name
local_var_name
Pylint ์ค์น
pip3 install pylint
Pylint ์ค์น ์์น ํ์ธ
which pylint
-
Preferences > Editor
- Code Style
- Line separator (for new files): Unix and OS X (\n)
- Right Margin (columns) : 140
- Code Style > Python > Other
- (check) Add line feed at the end of file
- (check) Use continuation indent for arguments
- Code Style
-
Preferences > External Tools
- "+" ๋ฒํผ์ ๋๋ฌ์ Pylint ์ถ๊ฐ
- Name: Pylint
- Program: which ๋ก ์ฐพ์ ๊ฒฝ๋ก ์ ๋ ฅ
- Parameters:
- Tools > External Tools > Pylint ์ฒดํฌ๋์ด ์๋์ง ํ์ธ
- "+" ๋ฒํผ์ ๋๋ฌ์ Pylint ์ถ๊ฐ
- PyPI์ ๋ฐฐํฌํ
ridi
๊ณ์ ์ ๋ฑ๋กํ ํจํค์ง์ Owner๋ก ์ถ๊ฐํ๋ค. - PyPI์ ๋ฑ๋กํ๋ ํจํค์ง๋ช
(setup.py์
name
ํ๋)์ridi-
๋ก ์์ํ๊ณ ์ฌ๋ฌ ๋จ์ด๋ก ์ด๋ฆ์ง์ด์ง ๊ฒฝ์ฐ-
(ํ์ดํ)์ผ๋ก ๊ตฌ๋ถํ๋ค.- ex)
ridi-cms-sdk
- ex)
- PyPI์ ํจํค์ง๋ช
๊ณผ import์ ์ฌ์ฉํ๋ ํจํค์ง๋ช
์ ๊ฐ๊ธ์ ์ผ์น์ํค๋, import ์ด๋ฆ์๋
-
๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค. - ์ต์์ ํจํค์ง ์ด๋ฆ์
ridi
๋ฅผ ์ฌ์ฉํ๋ค.# PyPI: ridi-cms-sdk # Directory tree: ridi/cms from ridi.cms import CmsClient
- ์ต์์ ํด๋ ๋๋ ํจํค์ง ์ด๋ฆ์ผ๋ก
ridi
๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค. - ์ฌ๋ด Library์ ์ต์์ ํจํค์ง ์ด๋ฆ์ดridi
์ด๋ฏ๋ก import ํธ๋ฉ๊ฐ ๋ฐ์ํ ์ ์๋ค.