• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    Python
  • Created about 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Learn and summarize 'Effective Python'

Effective Python

-- It's for Koreans. For non-koreans, please see other posts.

  • ใ€ŽํŒŒ์ด์ฌ ์ฝ”๋”ฉ์˜ ๊ธฐ์ˆ ใ€์˜ 59์žฅ์˜ ๋‚ด์šฉ์„ ํ•œ ์žฅ์”ฉ ์ •๋ฆฌ.

  • ์ฑ…์„ ๋Œ€์‹ ํ•ด์„œ ๋ณผ ์ˆ˜ ์žˆ์„ ์ •๋„๋กœ ๊ตฌ์ฒด์ ์œผ๋กœ ์˜ฎ๊น€.

  • ์ฑ… ๋ฒ„์ „์€ ์ดˆํŒ 2์‡„(2016-06-20).

  • V1 ์™„๋ฃŒ ๋‚ ์งœ: 2019-07-06

  • 40, 41 ์ฑ•ํ„ฐ๋Š” ๋ณธ์ธ์˜ ๋น„๋™๊ธฐ์— ๋Œ€ํ•œ ์ดํ•ด ๋ถ€์กฑ์œผ๋กœ ์•„์ง ๊ณต๋ถ€ ๋ชป ํ–ˆ์Œ. ํ–ฅํ›„ ์—…๋ฐ์ดํŠธ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.


๋ชฉ์ฐจ

1์žฅ. ํŒŒ์ด์ฌ๋‹ค์šด ์ƒ๊ฐ

  1. Better way 01. ์‚ฌ์šฉ ์ค‘์ธ ํŒŒ์ด์ฌ์˜ ๋ฒ„์ „์„ ์•Œ์ž
  2. Better way 02. PEP 8 ์Šคํƒ€์ผ ๊ฐ€์ด๋“œ๋ฅผ ๋”ฐ๋ฅด์ž
  3. Better way 03. bytes, str, unicode์˜ ์ฐจ์ด์ ์„ ์•Œ์ž
  4. Better way 04. ๋ณต์žกํ•œ ํ‘œํ˜„์‹ ๋Œ€์‹  ํ—ฌํผ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์ž
  5. Better way 05. ์‹œํ€€์Šค๋ฅผ ์Šฌ๋ผ์ด์Šคํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์ž
  6. Better way 06. ํ•œ ์Šฌ๋ผ์ด์Šค์— start, end, stride๋ฅผ ํ•จ๊ป˜ ์“ฐ์ง€ ๋ง์ž
  7. Better way 07. map๊ณผ filter ๋Œ€์‹ ์— ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์„ ์‚ฌ์šฉํ•˜์ž
  8. Better way 08. ๋ฆฌ์ŠคํŠธ ์ปดํ”„๋ฆฌํ—จ์…˜์—์„œ ํ‘œํ˜„์‹์„ ๋‘ ๊ฐœ ๋„˜๊ฒŒ ์“ฐ์ง€ ๋ง์ž
  9. Better way 09. ์ปดํ”„๋ฆฌํ—จ์…˜์ด ํด ๋•Œ๋Š” ์ œ๋„ˆ๋ ˆ์ดํ„ฐ ํ‘œํ˜„์‹์„ ๊ณ ๋ คํ•˜์ž
  10. Better way 10. range๋ณด๋‹ค๋Š” enumerate๋ฅผ ์‚ฌ์šฉํ•˜์ž
  11. Better way 11. ์ดํ„ฐ๋ ˆ์ดํ„ฐ๋ฅผ ๋ณ‘๋ ฌ๋กœ ์ฒ˜๋ฆฌํ•˜๋ ค๋ฉด zip์„ ์‚ฌ์šฉํ•˜์ž
  12. Better way 12. for์™€ while ๋ฃจํ”„ ๋’ค์—๋Š” else ๋ธ”๋ก์„ ์“ฐ์ง€ ๋ง์ž
  13. Better way 13. try/except/ese/finally์—์„œ ๊ฐ ๋ธ”๋ก์˜ ์žฅ์ ์„ ์ด์šฉํ•˜์ž

2์žฅ. ํ•จ์ˆ˜

  1. Better way 14. None์„ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋ณด๋‹ค ์˜ˆ์™ธ๋ฅผ ์ผ์œผํ‚ค์ž
  2. Better way 15. ํด๋กœ์ €๊ฐ€ ๋ณ€์ˆ˜ ์Šค์ฝ”ํ”„์™€ ์ƒํ˜ธ ์ž‘์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์ž
  3. Better way 16. ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋Œ€์‹  ์ œ๋„ˆ๋ ˆ์ดํ„ฐ๋ฅผ ๊ณ ๋ คํ•˜์ž
  4. Better way 17. ์ธ์ˆ˜๋ฅผ ์ˆœํšŒํ•  ๋•Œ๋Š” ๋ฐฉ์–ด์ ์œผ๋กœ ํ•˜์ž
  5. Better way 18. ๊ฐ€๋ณ€ ์œ„์น˜ ์ธ์ˆ˜๋กœ ๊น”๋”ํ•˜๊ฒŒ ๋ณด์ด๊ฒŒ ํ•˜์ž
  6. Better way 19. ํ‚ค์›Œ๋“œ ์ธ์ˆ˜๋กœ ์„ ํƒ์ ์ธ ๋™์ž‘์„ ์ œ๊ณตํ•˜์ž
  7. Better way 20. ๋™์  ๊ธฐ๋ณธ ์ธ์ˆ˜๋ฅผ ์ง€์ •ํ•˜๋ ค๋ฉด None๊ณผ docstring์„ ์‚ฌ์šฉํ•˜์ž
  8. Better way 21. ํ‚ค์›Œ๋“œ ์ „์šฉ ์ธ์ˆ˜๋กœ ๋ช…๋ฃŒ์„ฑ์„ ๊ฐ•์š”ํ•˜์ž

3์žฅ. ํด๋ž˜์Šค์™€ ์ƒ์†

  1. Better way 22. ๋”•์…”๋„ˆ๋ฆฌ์™€ ํŠœํ”Œ๋ณด๋‹ค๋Š” ํ—ฌํผ ํด๋ž˜์Šค๋กœ ๊ด€๋ฆฌํ•˜์ž
  2. Better way 23. ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ๊ฐ„๋‹จํ•˜๋ฉด ํด๋ž˜์Šค ๋Œ€์‹  ํ•จ์ˆ˜๋กœ ๋ฐ›์ž
  3. Better way 24. ๊ฐ์ฒด๋ฅผ ๋ฒ”์šฉ์œผ๋กœ ์ƒ์„ฑํ•˜๋ ค๋ฉด @classmethod ๋‹คํ˜•์„ฑ์„ ์ด์šฉํ•˜์ž
  4. Better way 25. super๋กœ ๋ถ€๋ชจ ํด๋ž˜์Šค๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜์ž
  5. Better way 26. ๋ฏน์Šค์ธ ์œ ํ‹ธ๋ฆฌํ‹ฐ ํด๋ž˜์Šค์—๋งŒ ๋‹ค์ค‘ ์ƒ์†์„ ์‚ฌ์šฉํ•˜์ž
  6. Better way 27. ๊ณต๊ฐœ ์†์„ฑ๋ณด๋‹ค๋Š” ๋น„๊ณต๊ฐœ ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์ž
  7. Better way 28. ์ปค์Šคํ…€ ์ปจํ…Œ์ด๋„ˆ ํƒ€์ž…์€ collection.abc์˜ ํด๋ž˜์Šค๋ฅผ ์ƒ์†๋ฐ›๊ฒŒ ๋งŒ๋“ค์ž.

4์žฅ. ๋ฉ”ํƒ€ํด๋ž˜์Šค์™€ ์†์„ฑ

  1. Better way 29. ๊ฒŒํ„ฐ์™€ ์„ธํ„ฐ ๋ฉ”์„œ๋“œ ๋Œ€์‹ ์— ์ผ๋ฐ˜ ์†์„ฑ์„ ์‚ฌ์šฉํ•˜์ž
  2. Better way 30. ์†์„ฑ์„ ๋ฆฌํŒฉํ† ๋งํ•˜๋Š” ๋Œ€์‹  @property๋ฅผ ๊ณ ๋ คํ•˜์ž
  3. Better way 31. ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ @property ๋ฉ”์„œ๋“œ์—๋Š” ๋””์Šคํฌ๋Ÿฝํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์ž
  4. Better way 32. ์ง€์—ฐ ์†์„ฑ์—๋Š” __getattr__, __getattribute__, __setattr__์„ ์‚ฌ์šฉํ•˜์ž
  5. Better way 33. ๋ฉ”ํƒ€ํด๋ž˜์Šค๋กœ ์„œ๋ธŒํด๋ž˜์Šค๋ฅผ ๊ฒ€์ฆํ•˜์ž
  6. Better way 34. ๋ฉ”ํƒ€ํด๋ž˜์Šค๋กœ ํด๋ž˜์Šค์˜ ์กด์žฌ๋ฅผ ๋“ฑ๋กํ•˜์ž
  7. Better way 35. ๋ฉ”ํƒ€ํด๋ž˜์Šค๋กœ ํด๋ž˜์Šค ์†์„ฑ์— ์ฃผ์„์„ ๋‹ฌ์ž

5์žฅ. ๋ณ‘ํ–‰์„ฑ๊ณผ ๋ณ‘๋ ฌ์„ฑ

  1. Better way 36. ์ž์‹ ํ”„๋กœ์„ธ์Šค๋ฅผ ๊ด€๋ฆฌํ•˜๋ ค๋ฉด subprocess๋ฅผ ์‚ฌ์šฉํ•˜์ž
  2. Better way 37. ์Šค๋ ˆ๋“œ๋ฅผ ๋ธ”๋กœํ‚น I/O์šฉ์œผ๋กœ ์‚ฌ์šฉํ•˜๊ณ  ๋ณ‘๋ ฌํ™”์šฉ์œผ๋กœ๋Š” ์‚ฌ์šฉํ•˜์ง€ ๋ง์ž
  3. Better way 38. ์Šค๋ ˆ๋“œ์—์„œ ๋ฐ์ดํ„ฐ ๊ฒฝ์Ÿ์„ ๋ง‰์œผ๋ ค๋ฉด Lock์„ ์‚ฌ์šฉํ•˜์ž
  4. Better way 39. ์Šค๋ ˆ๋“œ ๊ฐ„์˜ ์ž‘์—…์„ ์กฐ์œจํ•˜๋ ค๋ฉด Queue๋ฅผ ์‚ฌ์šฉํ•˜์ž
  5. [Better way 40. ๋งŽ์€ ํ•จ์ˆ˜๋ฅผ ๋™์‹œ์— ์‹คํ–‰ํ•˜๋ ค๋ฉด ์ฝ”๋ฃจํ‹ด์„ ๊ณ ๋ คํ•˜์ž][way40]
  6. [Better way 41. ์ง„์ •ํ•œ ๋ณ‘๋ ฌ์„ฑ์„ ์‹คํ˜„ํ•˜๋ ค๋ฉด concurrent.futures๋ฅผ ๊ณ ๋ คํ•˜์ž][way41]

6์žฅ. ๋‚ด์žฅ ๋ชจ๋“ˆ

  1. Better way 42. functions.wrap๋กœ ํ•จ์ˆ˜ ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์ •์˜ํ•˜์ž
  2. Better way 43. ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ try/finally ๋™์ž‘์„ ๋งŒ๋“ค๋ ค๋ฉด contextlib์™€ with๋ฌธ์„ ๊ณ ๋ คํ•˜์ž
  3. Better way 44. copyreg์œผ๋กœ pickle์„ ์‹ ๋ขฐํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์ž
  4. Better way 45. ์ง€์—ญ ์‹œ๊ฐ„์€ time์ด ์•„๋‹Œ datetime์œผ๋กœ ํ‘œํ˜„ํ•˜์ž
  5. Better way 46. ย ๋‚ด์žฅ ์•Œ๊ณ ๋ฆฌ์ฆ˜๊ณผ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜์ž
  6. Better way 47. ์ •๋ฐ€๋„๊ฐ€ ์ค‘์š”ํ•  ๋•Œ๋Š” decimal์„ ์‚ฌ์šฉํ•˜์ž
  7. Better way 48. ์ปค๋ฎค๋‹ˆํ‹ฐ์—์„œ ๋งŒ๋“  ๋ชจ๋“ˆ์„ ์–ด๋””์„œ ์ฐพ์•„์•ผ ํ•˜๋Š”์ง€ ์•Œ์•„๋‘์ž

7์žฅ. ํ˜‘๋ ฅ

  1. Better way 49. ๋ชจ๋“  ํ•จ์ˆ˜, ํด๋ž˜์Šค, ๋ชจ๋“ˆ์— docstring์„ ์ž‘์„ฑํ•˜์ž
  2. Better way 50. ๋ชจ๋“ˆ์„ ๊ตฌ์„ฑํ•˜๊ณ  ์•ˆ์ •์ ์ธ API๋ฅผ ์ œ๊ณตํ•˜๋ ค๋ฉด ํŒจํ‚ค์ง€๋ฅผ ์‚ฌ์šฉํ•˜์ž
  3. Better way 51. ๋ฃจํŠธ Exception์„ ์ •์˜ํ•ด์„œ API๋กœ๋ถ€ํ„ฐ ํ˜ธ์ถœ์ž๋ฅผ ๋ณดํ˜ธํ•˜์ž
  4. Better way 52. ์ˆœํ™˜ ์˜์กด์„ฑ์„ ์—†์• ๋Š” ๋ฐฉ๋ฒ•์„ ์•Œ์ž
  5. Better way 53. ์˜์กด์„ฑ์„ ๋ถ„๋ฆฌํ•˜๊ณ  ์žฌํ˜„ํ•˜๋ ค๋ฉด ๊ฐ€์ƒ ํ™˜๊ฒฝ์„ ์‚ฌ์šฉํ•˜์ž

8์žฅ. ์ œํ’ˆํ™”

  1. Better way 54. ๋ฐฐํฌ ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•˜๋Š” ๋ฐ๋Š” ๋ชจ๋“ˆ ์Šค์ฝ”ํ”„ ์ฝ”๋“œ๋ฅผ ๊ณ ๋ คํ•˜์ž
  2. Better way 55. ๋””๋ฒ„๊น… ์ถœ๋ ฅ์šฉ์œผ๋กœ๋Š” repr ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•˜์ž
  3. Better way 56. unittest๋กœ ๋ชจ๋“  ๊ฒƒ์„ ํ…Œ์ŠคํŠธํ•˜์ž
  4. Better way 57. pdb๋ฅผ ์ด์šฉํ•œ ๋Œ€ํ™”์‹ ๋””๋ฒ„๊น…์„ ๊ณ ๋ คํ•˜์ž
  5. Better way 58. ์ตœ์ ํ™”ํ•˜๊ธฐ ์ „์— ํ”„๋กœํŒŒ์ผํ•˜์ž
  6. Better way 59. tracemalloc์œผ๋กœ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ ํ˜„ํ™ฉ๊ณผ ๋ˆ„์ˆ˜๋ฅผ ํŒŒ์•…ํ•˜์ž

์‹œ ํ•˜๋‚˜ ์ฝ๊ณ  ๊ฐ€์„ธ์š”.

์‚ฌ๋ž‘ํ–ˆ๋˜ ๋‚˜์˜ ๋งˆ์Œ ์†์— ์ž‘์€ ๊ฟˆ ํ•˜๋‚˜๋งŒ์„ ๋‚จ๊ฒจ๋‘๊ณ  ๋„ˆ๋ฌด ์‰ฝ๊ฒŒ ๋– ๋‚˜๋ฒ„๋ฆฐ ๋„ˆ๋ฅผ ์ด์ œ๋Š” ์ดํ•ดํ•˜๋ ค ํ•ด. -- ๋‹ฌ๋งˆ๋„์‚ฌ ๊น€ํ˜ˆ๊ตญ