본문 바로가기

분류 전체보기980

Python Argparse: '--help'에 기본값을 포함하는 방법은 무엇인가요?, Argparse: Way to include default values in '--help'? 질문 다음과 같은 argparse 스니펫이 있다고 가정해 봅시다: diags.cmdln_parser.add_argument( '--scan-time', action = 'store', nargs = '?', type = int, default = 5, help = "Wait SCAN-TIME seconds between status checks.") 현재, --help는 다음과 같이 반환됩니다: usage: connection_check.py [-h] [--version] [--scan-time [SCAN_TIME]] Test the reliability/uptime of a connection. optional arguments: -h, --help 도움말을 표시하고 종료 --version 프로그램의 .. 2023. 11. 28.
Python에서 쉼표로 분할하고 공백을 제거하는 방법은 무엇인가요?, How to split by comma and strip white spaces in Python? 질문 나는 쉼표로 나누지만 공백을 제거하지 않는 몇 가지 파이썬 코드가 있습니다: >>> string = "blah, lots , of , spaces, here " >>> mylist = string.split(',') >>> print mylist ['blah', ' lots ', ' of ', ' spaces', ' here '] 저는 이렇게 공백이 제거된 결과를 원합니다: ['blah', 'lots', 'of', 'spaces', 'here'] 리스트를 반복하고 각 항목을 strip()할 수도 있지만, 파이썬이기 때문에 더 빠르고 쉽고 우아한 방법이 있을 것이라고 생각합니다. 답변 리스트 컴프리헨션을 사용하세요 - 더 간단하고 for 루프만큼 읽기 쉽습니다. my_string = "blah, lo.. 2023. 11. 28.
Python 3에서 execfile의 대체 방법은 무엇인가요?, What is an alternative to execfile in Python 3? 질문 파이썬 3에서는 execfile()을(를) 제거하여 스크립트를 빠르게 로드하는 모든 쉬운 방법이 취소되었는 것 같습니다. 빠뜨린 명백한 대안이 있을까요? 답변 문서에 따르면, 다음 대신에 execfile("./filename") 다음을 사용하세요 exec(open("./filename").read()) 참조: 파이썬 3.0에서의 새로운 내용 execfile exec 2023. 11. 24.
Python 오류 "filename.whl은(는) 이 플랫폼에서 지원되지 않는 휠입니다.", Error "filename.whl is not a supported wheel on this platform" 질문 저는 로컬 드라이브에 저장된 scipy-0.15.1-cp33-none-win_amd64.whl을 설치하고 싶습니다. 저는 다음을 사용하고 있습니다: pip 6.0.8 from C:\Python27\Lib\site-packages python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] 다음을 실행할 때: pip install scipy-0.15.1-cp33-none-win_amd64.whl 다음과 같은 오류가 발생합니다: scipy-0.15.1-cp33-none-win_amd64.whl은(는) 이 플랫폼에서 지원되지 않는 휠입니다 문제가 무엇인가요? 답변 cp33는 CPython 3.3을 의미합니다. 대신 scipy‑0.15.. 2023. 11. 24.