여기서 내가 잘못하고있는 것이 확실하지 않습니까? \를 특수 문자로 처리해야합니까? 문자열 \ r \ n은 문자 그대로 txt 파일의 문자열에 나타납니다./r/n 하위 문자열을 찾음으로써 문자열 데이터를리스트 목록으로 나눕니다
def split_into_rows(weather_data):
list_of_rows = []
while not (weather_data.find("\r\n") == -1):
firstreturnchar = weather_data.find("\r\n")
row = weather_data[ :firstreturnchar]
list_of_rows = list_of_rows.append(row)
return list_of_rows
내가 거기에 문자열 \ r에 \의 예는 여전히 n은 문자열의 왼쪽 부분 문자열의 첫 번째 인스턴스를 찾는 동안,이다 필요한 것은 "\ 연구 \ n을", 그 전에 모든 것을 잘라 넣어 그것을 변수 행에 넣은 다음, 행을 list_of_rows에 추가하십시오.
'list_of_rows = list_of_rows.append (행) ':이 목록은 당신이 weather_data.splitlines'를 통해 단지 그렇게 할 수 변경할 수 – Mangohero1
참고하며, 할당을 필요로하지 않습니다()' – GPhilo
백 슬래시를 이스케이프 처리해야합니다 (앞에서 다른 백 슬래시를 입력하십시오). '\ r'과'\ n'는 모두 특수 문자입니다. [이 비슷한 질문.] (https://stackoverflow.com/questions/11331778/find-backslash-in-a-string-python) – colopop