va = 1 vb = 2 n = 3 import pdb pdb.set_trace() 위 코드를 실행고나서 중단점 걸린다음 va 입력하면 1이 출력될거고 vb 입력하면 2가 출력될거다. 그다음 n을 입력하면 사용자 입장에서는 n 이라는 변수값을 확인하고 싶은 의도로 입력했겠지만, pdb 는 n을 입력받으면 다음 라인으로 건너뛰게 된다. 단순히 n의 값을 출력해보는거라면 p n 이라고 입력하면 그 값을 확인할 수 있긴하다. 그런데 n의 값을 수정해주고 싶을때는 어떻게 해야할까? p 는 단순히 출력만을 위해 사용되는 pdb 전용 커맨드이다. n += 3을 해보면 역시나 다음 라인으로 넘어간다. 보다 범용적으로 pdb 디버깅 커맨드를 무시하면서 디버깅을 할 수 있는 방법은 맨 앞에 !를 붙이고 값을 확인하고 싶..
class Foo: def __init__(self): pass def getx(self): return self.x foo = Foo() foo.x = 1 print(foo.getx()) C++ 로 위와 같이 코드를 작성했으면 foo.x = 1 라인에서 아래와 같은 오류가 출력됐을것이다. error: ‘class Foo’ has no member named ‘x’ 근데 Python 에서는 에러가 안난다. 저렇게 하면 없던 멤버변수 x 가 생긴다. 실제 사용 예 YOLOv8 에서 nn.Sequential 클래스의 객체에 i, f, type 이라는 멤버변수를 위 방법을 이용해 정의한다. https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn..
python의 Built-in Functions 중 eval 이라는 함수가 있다. eval 은 문자열을 입력으로 받는다. eval 의 출력은 입력받은 문자열이 Python interpreter로 해독가능하다면 그 문자열을 "코드"로 보고 실행한다. 그렇지 않은 경우는 예외가 발생한다. eval('1+2') # 3 eval("'1'+'2'") # "12" 이런것도 가능하다. class Foo: def __init__(self, x): self.x = x pass foo = eval("Foo(x=5)") print(foo.x) # 5 too = eval("Foo")(15) print(too.x) # 15 활용 방법은 무궁무진하다. 실제 사용 예 YOLOv8 의 경우 모델 아키텍쳐가 컨피그 파일에 정의돼있다...
클래스의 함수 바깥에서 변수를 정의하면 이 변수는 static 멤버변수가 된다. 이 변수를 static 멤버변수로서 값을 수정하고 싶다면 클래스이름.변수 로 접근하여 수정해야한다. 그렇지않고 self.변수 나 객체.변수 이런식으로 값을 수정하게 되면 static의 특성을 잃고 멤버 변수로써 재정의가 된다. 아래의 예제코드에서 foo.x 가 static 멤버변수이다. class foo(object): x = 'original' def __init__(self): self.y = 'hi' def setx(self, x): foo.x = x c1 = foo() print(c1.x) # original print(c1.y) # hi c2 = foo() print(c2.x) # original print(c2.y..
conda update conda conda update anaconda https://docs.anaconda.com/anaconda/install/update-version/ Updating from older versions — Anaconda documentation Updating from older versions Follow the instructions below to update Anaconda to the latest version. Windows: Open Anaconda Prompt. macOS or Linux: Open a terminal window. To update to the latest version of Anaconda, enter these commands: #upda..
https://stackoverflow.com/questions/3229419/how-to-pretty-print-nested-dictionaries How to pretty print nested dictionaries? How can I pretty print a dictionary with depth of ~4 in Python? I tried pretty printing with pprint(), but it did not work: import pprint pp = pprint.PrettyPrinter(indent=4) pp.pprint(mydict) I ... stackoverflow.com
with open(filename) as f: mylist = f.read().splitlines() https://stackoverflow.com/questions/15233340/getting-rid-of-n-when-using-readlines Getting rid of \n when using .readlines() I have a .txt file with values in it. The values are listed like so: Value1 Value2 Value3 Value4 My goal is to put the values in a list. When I do so, the list looks like this: ['Value1\n', 'Value... stackoverflow.com
- Total
- Today
- Yesterday
- 백준
- C++ Deploy
- 백준 11053
- ㅂ
- 백준 1766
- 이분탐색
- 자료구조
- LCA
- 순열
- 백준 11437
- MOT
- 조합
- 단축키
- 파이참
- cosine
- FairMOT
- 문제집
- 백트래킹
- Lowest Common Ancestor
- 위상 정렬 알고리즘
- 가장 긴 증가하는 부분 수열
- 인공지능을 위한 선형대수
- PyCharm
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |

