作者scccc (廖小刀)
看板Python
标题[问题] 请问正python读值的问题
时间Fri Jan 11 11:12:30 2008
我是python的新新新手
我有现在有一个问题
1.我在读网页原史码时要抓其中一行的值,但我只要那一行值不要前後的空白
ex.
import urllib
page = urllib.urlopen("
http://tw.yaho.com")
lines = page.readlines()
page.close()
filename = "test.txt"
b = 0
for i in lines:
b = b+1
if b == 252:
print i
test = i
filehandle = open(filename, 'a')
filehandle.write(' \n test \n '+ test)
filehandle.close()
如果252行前面有空白的话要如何让test只有252行的值而不加前面的空白
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.104.50.246
1F:推 Tiberius:i.strip() 01/11 12:40
2F:→ scccc:能说一下用法吗?或用个范例?谢谢!! 01/14 13:53
3F:→ scccc:我找到使用方试了~谢谢您!! 01/14 14:05