要知道現在的資料結構是什麼可以使用

type()

peicheng@PCsNB ~/project/python/chinese $ cat readr3.py 
#coding=utf-8

f=open('rec2','r')
lines=f.readlines()

print type(lines)
for line in lines:
print line,

print type(line)
print line,
line=line.decode('utf-8').rstrip()
print len(line)
print type(line)



result

peicheng@PCsNB ~/project/python/chinese $ python readr3.py 
<type 'list'>
test1
test2
<type 'str'>
test2
5
<type 'unicode'>


arrow
arrow
    全站熱搜

    peicheng 發表在 痞客邦 留言(0) 人氣()