Skip to main content
 首页 » 编程设计

python之读取字符串的第 x 行

2025年05月04日21insus

<分区>

Possible Duplicate:
get nth line of string in python

有没有办法从 Python 中的多行字符串中获取指定行?例如:

>>> someString = 'Hello\nthere\npeople\nof\nEarth' 
>>> aNewString = someString.line(1) 
>>> print aNewString 
there 

我想制作一个简单的“解释器”风格的脚本,循环遍历它所提供的文件的每一行。