作者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
推 Tiberius:i.strip() 01/11 12:40
→ scccc:能說一下用法嗎?或用個範例?謝謝!! 01/14 13:53
→ scccc:我找到使用方試了~謝謝您!! 01/14 14:05