String18 Python "Jun 1 2005 1:33PM" 문자열을 날짜 및 시간으로 변환하세요., Convert string "Jun 1 2005 1:33PM" into datetime 질문 다음 문자열을 datetime 객체로 변환하는 방법은 무엇인가요? "Jun 1 2005 1:33PM" 답변 datetime.strptime은 사용자가 지정한 형식으로 입력 문자열을 구문 분석하여 timezone-naive datetime 객체로 변환합니다: >>> from datetime import datetime >>> datetime.strptime('Jun 1 2005 1:33PM', '%b %d %Y %I:%M%p') datetime.datetime(2005, 6, 1, 13, 33) 기존의 datetime 객체를 사용하여 date 객체를 얻으려면 .date()를 사용하여 변환하십시오: >>> datetime.strptime('Jun 1 2005', '%b %d %Y').date() dat.. 2023. 5. 6. Python 바이트를 문자열로 변환하세요., Convert bytes to a string 질문 외부 프로그램의 표준 출력을 bytes 객체로 캡처했습니다: >>> from subprocess import * >>> command_stdout = Popen(['ls', '-l'], stdout=PIPE).communicate()[0] >>> >>> command_stdout b'total 0\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file1\n-rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file2\n' 그것을 일반적인 Python 문자열로 변환하여 다음과 같이 출력하려고합니다: >>> print(command_stdout) -rw-rw-r-- 1 thomas thomas 0 Mar 3 07:03 file1 -rw-rw-r-- 1 .. 2023. 5. 5. 이전 1 2 3 4 5 다음