본문 바로가기

Python Basic16

closure 사용법 https://dojang.io/mod/page/view.php?id=2364 파이썬 코딩 도장: 33.1 변수의 사용 범위 알아보기 Unit 33. 클로저 사용하기 이번에는 변수의 사용 범위와 함수를 클로저 형태로 만드는 방법을 알아보겠습니다. 참고로 클로저는 개념이 다소 어려울 수 있으므로 변수의 사용 범위부터 알아본 뒤 dojang.io 함수안의 함수 def print_hello(): hello = 'Hello, world!' def print_message(): print(hello) print_message() print_hello() 클로저 클로저를 사용하면 프로그램의 흐름을 변수에 저장할 수 있습니다. 즉, 클로저는 지역 변수와 코드를 묶어서 사용하고 싶을 때 활용합니다. 또한, 클로저에 속.. 2022. 11. 23.
[ Think Python ] function object A function object is a value you can assign to a variable or pass as an argument. For example, do_twice is a function that takes a function object as an argument and calls it twice: Here’s an example that uses do_twice to call a function named print_spam twice: def do_twice(f): f() f() def print_spam(): print('spam') print('spam') do_twice(print_spam) Exercise 3-2. 1. Type this example into a sc.. 2022. 11. 20.
Programming productivity tools Think of it as a mini awesome list of programming productivity tools: Utility Description jq https://stedolan.github.io/jq/ Utility for manipulating data in the form of JSON documents. Extremely useful for manipulating the output of web APIs directly in the shell. Data is read from standard input and results are printed on standard output. Manipulation is described through a custom domain-specif.. 2022. 11. 8.
Debugging post- mortem debugging 1) 디버깅 모드로 파일 실행 $ python3 -i 2) 디버깅으로 진입 sys.last_traceback 에서 찾은 traceback 의 포스트-모템(post-mortem) 디버깅으로 진입합니다. >>> import pdb >>> pdb.pm() 인터프리터에서 디버깅 실행 >>> import pdb >>> import mymodule >>> pdb.run('mymodule.test()') 실행을 재개하는 아무 명령 (continue, step, next, return, jump, quit 및 해당 명령의 약어들)을 사용 가능 help(h) 기능을 이용하여 단축키 확인 가능 코드에서 breakpoint 사용 import pdb; pdb.set_trace() im.. 2022. 11. 8.