저는 Python을 처음 접했고이 문제를 파이썬으로 생각하는 데 어려움이 있습니다. SMS 메시지의 텍스트 파일이 있습니다. 캡처하려는 다중 행 문이 있습니다.Python의 라인 패턴 결정
import fileinput
parsed = {}
for linenum, line in enumerate(fileinput.input()):
### Process the input data ###
try:
parsed[linenum] = line
except (KeyError, TypeError, ValueError):
value = None
###############################################
### Now have dict with value: "data" pairing ##
### for every text message in the archive #####
###############################################
for item in parsed:
sent_or_rcvd = parsed[item][:4]
if sent_or_rcvd != "rcvd" and sent_or_rcvd != "sent" and sent_or_rcvd != '--\n':
###########################################
### Know we have a second or third line ###
###########################################
하지만 여기서 나는 벽에 닿았습니다. 여기서 얻은 문자열을 포함하는 가장 좋은 방법이 무엇인지 모르겠습니다. 나는 전문가의 조언을 좋아한다. Python 2.7.3을 사용했지만 기꺼이 3으로 이동하십시오.
목표 :이 SMS에서 사람이 읽을 수있는 파일로 3 행의 전체 인용 부호를 사용하십시오.
예 텍스트 :
12425234123|2011-03-19 11:03:44|words words words words
12425234123|2011-03-19 11:04:27|words words words words
12425234123|2011-03-19 11:05:04|words words words words
12482904328|2011-03-19 11:13:31|words words words words
--
12482904328|2011-03-19 15:50:48|More bolder than flow
More cumbersome than pleasure;
Goodbye rocky dump
--
(.. 당신이 그 똥에 대한 하이쿠이야 구하기 전에 네, 내 가장 친한 친구를 문자 메시지의 지난 5 년간을 캡처하기 위해 노력하고있어)
이상적인 결과는 다음과 같습니다.
Haipu 3
2011-03-19
More bolder than flow
More cumbersome than pleasure;
Goodbye rocky dump
당신이 입력의 예를 준 당신이 우리에게 입력하는 간단한 예제를 줄 수 출력 –
을 예상하는 경우가 helfpul 것 파일 및 출력으로 기대되는 내용은 무엇입니까? thx – jrjc