Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pragmatic Python

Pragmatic Python

2018 Django Girls Seoul 4월 세미나에서 발표한 [Pragmatic Python] 발표 자료입니다.

Sunghyun Hwang

April 30, 2018
Tweet

More Decks by Sunghyun Hwang

Other Decks in Technology

Transcript

  1. 2 ടࢿഅ Sunghyun Hwang • Software Engineer at Rainist Co.,

    Ltd. • Python 2014 ~ • Scala 2017 ~ • Microservice Architecture 2017 ~ • Email: [email protected] • Twitter: @_sunghyunzz • Github: @sunghyunzz
  2. import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) import

    unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) 4
  3. import unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) import

    unittest class PragmaticPythonTest(unittest.TestCase): def test_is_python_pragmatic(self): self.assertTrue( are_many_companies_using_python('KR') ) 5
  4. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 9
  5. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 10
  6. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 11
  7. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') fetch_nr_of_jobs('Server+Developer') 12
  8. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') 13
  9. import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int:

    r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 import requests URL = 'https://www.wanted.co.kr/api/v3/search?country=KR' def fetch_nr_of_jobs(q: str) -> int: r = requests.get(f'{URL}&query={q}') return r.json()['data']['jobs']['total'] fetch_nr_of_jobs('Python+Developer') # 115 fetch_nr_of_jobs('Server+Developer') # 269 14
  10. 15

  11. (…) Simple is better than complex. (…) Readability counts. (…)

    If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 17 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/
  12. (…) Simple is better than complex. (…) Readability counts. (…)

    If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 18 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/
  13. (…) Simple is better than complex.. (…) Readability counts. (…)

    If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) (…) Simple is better than complex. (…) Readability counts. (…) If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. (…) 19 PEP 20 — The Zen of Python https://www.python.org/dev/peps/pep-0020/
  14. 21 s = {1, 2, 3} print(4 in s) l

    = [1, 2] * 5 print(l[:-1]) d = {1: 1, 2: 4, 3: 9} print(d[3])
  15. 23 l = [1, 2, 3, 4, 5] d =

    { i: i ** i for i in l if i % 2 == 1 }
  16. 24 def fib(n): a, b = 0, 1 for i

    in range(n): a, b = b, a + b return a
  17. 25 from itertools import permutations data = [1, 2, 3]

    for case in permutations(data): pass
  18. 32 Card Recommendation O(NC * NG * NB * NS)

    • NC = number of cards • NG = number of benefit groups per card • NB = number of benefits per benefit group • NS = number of user spendings
  19. 33 import timeit def calc(): s = 0 for i

    in range(10 ** 8): s += i return s print( timeit.timeit( "calc()", setup="from __main__ import calc", number=1 ) )
  20. 34 import timeit def calc(): s = 0 for i

    in range(10 ** 8): s += i return s print( timeit.timeit( "calc()", setup="from __main__ import calc", number=1 ) ) 7.25s
  21. 35 val t1 = System.nanoTime() var s: Long = 0

    for (i ← 1 to 100000000) { s += i } val t2 = System.nanoTime() println((t2 - t1) / 1000000000.0)
  22. 36 val t1 = System.nanoTime() var s: Long = 0

    for (i ← 1 to 100000000) { s += i } val t2 = System.nanoTime() println((t2 - t1) / 1000000000.0) 0.36s
  23. 38

  24. 39

  25. 45 https://www.redhat.com/en/blog/state-microservices Respondents believe in “using the right tool for

    the right task” According to 44% Middleware respondents & 50% OpenShift respondents
  26. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 48
  27. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 49
  28. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 50
  29. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 51
  30. 52

  31. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 53
  32. Prototyping I/O HTTP API Tasks (script) Data Science & Analysis

    Small Functions in MSA Prototyping I/O HTTP API Tasks (script) Data Science & Analysis Small Functions in MSA 54
  33. 58 Join Us! https://rainist.com/recruit/engineer • Back-end Engineer (Python/Scala) • Devops

    Engineer • Data Engineer • Data Scientist • Growth Hacker • Web Front-end Engineer • Android Engineer • iOS Engineer • QA Engineer • Security Engineer