티스토리 뷰
https://stackoverflow.com/a/22156138
How can I replace `eval` in my function?
I know very well that it is not good practice using eval in Python. Here is my code: from hashlib import * # added for clarification def get_hash(self): if self.hash_type in ['md5', 'sha1', '
stackoverflow.com
eval 기반 구현
from hashlib import * # added for clarification
def get_hash(self):
if self.hash_type in ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']:
data = eval(self.hash_type) # <--- how can I replace this?
getattr 기반 구현
import hashlib
if self.hash_type in ['md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512']:
func = getattr(hashlib, self.hash_type)
YOLOv8 기여하는데 쓰임
https://github.com/ultralytics/ultralytics/pull/1273
remove eval in parse_model by developer0hye · Pull Request #1273 · ultralytics/ultralytics
I made an effort to minimize the number of calls to the eval() function in parse_model() in order to make the code safer. It is related to #955.
github.com
'Python' 카테고리의 다른 글
| [Python] PDB 사용시 List comprehension 에러 (0) | 2023.04.11 |
|---|---|
| [Python] eval 사용을 피하는 방법 2. locals() 혹은 globals() (0) | 2023.03.06 |
| Anaconda 에서 miniconda 로 갈아타다. (0) | 2023.03.04 |
| [Python] Black 과 pre-commit 으로 일관된 포맷으로 코드를 관리하자 (0) | 2023.02.17 |
| [Python] auto-formatter black 맛보기 (0) | 2023.02.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 문제집
- 백준 1766
- Lowest Common Ancestor
- 파이참
- 조합
- PyCharm
- 순열
- 백준 11437
- LCA
- 이분탐색
- FairMOT
- 백준
- ㅂ
- 백트래킹
- 인공지능을 위한 선형대수
- MOT
- 가장 긴 증가하는 부분 수열
- 자료구조
- 위상 정렬 알고리즘
- cosine
- 백준 11053
- C++ Deploy
- 단축키
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
글 보관함
