请问这里writer = codecs.lookup ('utf-8')[3](file)的参数"3"是何意?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

请问这里writer = codecs.lookup ('utf-8')[3](file)的参数"3"是何意?

Deng Patrick
import sys
import codecs
 
file = open("result.xml", 'w')
writer = codecs.lookup ('utf-8')[3](file)

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问这里writer = codecs.lookup ('utf-8')[3](file)的参数"3"是何意?

clfff.peter
打下面语句试试,就知道了。
print codecs.lookup ('utf-8')

 
2007/11/17, Deng Patrick <[hidden email]>:
import sys
import codecs
 
file = open("result.xml", 'w')
writer = codecs.lookup ('utf-8')[3](file)

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问这里writer = codecs.lookup ('utf-8')[3](file)的参数"3"是何意?

tkdchen
In reply to this post by Deng Patrick
2007/11/17, Deng Patrick <[hidden email]>:
> import sys
> import codecs
>
> file = open("result.xml", 'w')
> writer = codecs.lookup ('utf-8')[3](file)

可以这样分开写,更清楚些。
ref = codecs.lookup("utf-8")[3] # 取得utf8编码的StreamWriter类对象引用
writer = ref(file) #创建一个StreamWriter类实例,要求给构造函数传入一个file-like对象

使用codecs.lookup方法能够获得与一种编码相关的多个对象引用,codecs模块中有其他函数能够简化lookup方法的使用。

请参阅:
http://docs.python.org/lib/module-codecs.html
http://tkdchen.spaces.live.com/blog/cns!36EC325D5602B064!498.entry

--
GoogleTalk: [hidden email]
MSN: [hidden email]
My Space: tkdchen.spaces.live.com
BOINC: boinc.berkeley.edu
中国分布式计算总站: www.equn.com
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问这里writer = codecs.lookup ('utf-8')[3](file)的参数"3"是何意?

QiJie Shen
In reply to this post by Deng Patrick
是index3, 表示一个序列对象的第4个(index由0开始)

2007/11/17, Deng Patrick <[hidden email]>:
import sys
import codecs
 
file = open("result.xml", 'w')
writer = codecs.lookup ('utf-8')[3](file)

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to   [hidden email]
Detail Info: <a onclick="return top.js.OpenExtLink(window,event,this)" href="http://python.cn/mailman/listinfo/python-chinese" target="_blank"> http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese