가능한 중복 :
get nth line of string in python문자열 x의 문자열을 읽으시겠습니까?
는 파이썬에서 여러 줄 문자열에서 지정된 행을 얻을 수있는 방법이 있나요? 예를 들면 :
>>> someString = 'Hello\nthere\npeople\nof\nEarth'
>>> aNewString = someString.line(1)
>>> print aNewString
there
내가이 공급됩니다 파일의 모든 라인을 통해 루프, 간단한 "인터프리터"스타일 스크립트를하고 싶습니다
['str.split' (http://docs.python.org/library/stdtypes.html#str.split) 및/또는'str.splitlines' (http://docs.python.org/library/stdtype sghtml # str.splitlines) –
사실, 간단한 인터프리터를 만들고 싶다면 처음에는 개행 문자로 가득 찬 문자열을 얻고 싶지 않을 것입니다. 대신'script = scriptfile.read(); ...; line in line : scriptfile :'에''do'을 입력하십시오. – abarnert