2008年01月15日 星期二 11:12
Ò»¸ö±äÁ¿¿ÉÒÔ±»¸³ÓèÈκÎÀàÐ͵ÄÖµ£¬ÎÒÈçºÎÖªµÀµ±Ç°Õâ¸ö±äÁ¿ÊÇʲôÀàÐÍÄØ£¿ a = 11 a = '11' ÈçºÎÖªµÀaµ±Ç°ÊÇʲôÀàÐÍ£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080115/e4a5001d/attachment.html
2008年01月15日 星期二 11:34
2008/1/15 kun xu <coonxu在gmail.com>: > 一个变量可以被赋予任何类型的值,我如何知道当前这个变量是什么类型呢? > > a = 11 > a = '11' > > 如何知道a当前是什么类型? > >>> def printtype(data): ... if isinstance(data, int): ... print 'int' ... elif isinstance(data, str): ... print 'str' ... >>> printtype(11) int >>> printtype('11') str >>> -- Best Regards, Leo Jay
2008年01月15日 星期二 11:36
type(a) ÔÚ08-1-15£¬kun xu <coonxu在gmail.com> дµÀ£º > > Ò»¸ö±äÁ¿¿ÉÒÔ±»¸³ÓèÈκÎÀàÐ͵ÄÖµ£¬ÎÒÈçºÎÖªµÀµ±Ç°Õâ¸ö±äÁ¿ÊÇʲôÀàÐÍÄØ£¿ > > a = 11 > a = '11' > > ÈçºÎÖªµÀaµ±Ç°ÊÇʲôÀàÐÍ£¿ > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080115/8a24a3e0/attachment.htm
2008年01月15日 星期二 12:05
Çë½Ìһϣ¬ÈçºÎÅжÏÒ»¸öÎļþÊÇASCIIÂïÄØ£¬»¹ÊÇunicode»òÕßÊÇiso8859-1µÈµÈÕâ Щ±àÂë ¾ÍÊÇÏ൱ÓÚlinuxÖеÄfileµÄ²¿·Ö¹¦ÄÜ -------------- 下一部分 -------------- Ò»¸ö·ÇÎı¾¸½¼þ±»Çå³ý... ·¢ÐÅÈË: %(who)s Ö÷Ìâ: %(subject)s ÈÕÆÚ: %(date)s ´óС: 235 Url: http://python.cn/pipermail/python-chinese/attachments/20080115/fe913603/attachment.vcf
2008年01月15日 星期二 12:17
OT: 估计你又被盖茨的 Notepad.exe 迷惑了,
Notepad.exe 编码类型里的名称是某翻译公司乱翻译的,
它的 ASCII 其实是 GB18030,
而它的所谓 UNICODE 其实是带该死 Bom 头的 UTF-16。
这里给你贴一段简单猜测编码的
encc=''
def zh2utf8(stri):
"""Auto converter encodings to utf8
It will test utf8,gbk,big5,jp,kr to converter"""
global encc
for c in ('utf-8', 'gbk', 'big5', 'jp', 'euc_kr','utf16','utf32'):
encc = c
try:
return stri.decode(c).encode('utf8')
except:
pass
encc = 'unk'
return stri
def zh2unicode(stri):
"""Auto converter encodings to unicode
It will test utf8,gbk,big5,jp,kr to converter"""
global encc
for c in ('utf-8', 'gbk', 'big5', 'jp', 'euc_kr','utf16','utf32'):
encc = c
try:
return stri.decode(c)
except:
pass
encc = 'unk'
return stri
2008/1/15 吴亮 <garcia.relax at gmail.com>:
> 请教一下,如何判断一个文件是ASCII嘛呢,还是unicode或者是iso8859-1等等这
> 些编码
> 就是相当于linux中的file的部分功能
>
2008年01月15日 星期二 12:23
Jiahua Huang wrote:
> OT: 估计你又被盖茨的 Notepad.exe 迷惑了,
>
> Notepad.exe 编码类型里的名称是某翻译公司乱翻译的,
> 它的 ASCII 其实是 GB18030,
> 而它的所谓 UNICODE 其实是带该死 Bom 头的 UTF-16。
>
>
> 这里给你贴一段简单猜测编码的
>
> encc=''
> def zh2utf8(stri):
> """Auto converter encodings to utf8
>
> It will test utf8,gbk,big5,jp,kr to converter"""
> global encc
> for c in ('utf-8', 'gbk', 'big5', 'jp', 'euc_kr','utf16','utf32'):
> encc = c
> try:
> return stri.decode(c).encode('utf8')
> except:
> pass
> encc = 'unk'
> return stri
>
> def zh2unicode(stri):
> """Auto converter encodings to unicode
>
> It will test utf8,gbk,big5,jp,kr to converter"""
> global encc
> for c in ('utf-8', 'gbk', 'big5', 'jp', 'euc_kr','utf16','utf32'):
> encc = c
> try:
> return stri.decode(c)
> except:
> pass
> encc = 'unk'
> return stri
>
>
> 2008/1/15 吴亮 <garcia.relax在gmail.com>:
>
>> 请教一下,如何判断一个文件是ASCII嘛呢,还是unicode或者是iso8859-1等等这
>> 些编码
>> 就是相当于linux中的file的部分功能
>>
>>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
谢谢!
PS:我是用此来比较两个文本的内容的,这两个文本编码可能不一样,所以我得判
断一下它们的编码,然后转换成同一种编码进行比较
我用的是Linux(好久没用过windows了,所以好像和notepad.exe没什么关系吧,
呵呵)
-------------- 下一部分 --------------
一个非文本附件被清除...
发信人: %(who)s
主题: %(subject)s
日期: %(date)s
大小: 235
Url: http://python.cn/pipermail/python-chinese/attachments/20080115/08e19f37/attachment.vcf
2008年01月15日 星期二 12:38
没啥, 只是一般只有用 Notepad 的人才以为 unicode 是编码。 你的需求直接用我贴的代码就可以啦, 管你啥编码的玩意都一律转为 utf8 str 或 unicode 2008/1/15 吴亮 <garcia.relax at gmail.com>: > 我用的是Linux(好久没用过windows了,所以好像和notepad.exe没什么关系吧, > 呵呵)
2008年01月15日 星期二 15:28
RT£¬ÒòΪEÎIJ»Õ¦µØ£¬ËùÒÔÏëÎÊһϣ¬ÓÐûÓÐÖÐÎĵĽ̳̣¿Ð»Ð»£¡ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080115/ea4858d9/attachment.html
2008年01月15日 星期二 16:58
import types
if type(a)==types.IntType:
print "Int type"
2008年01月15日 星期二 19:14
2008/1/15 doudou doudou <array.doudou在gmail.com>: > import types > if type(a)==types.IntType: > print "Int type" 使用types.IntType这种比较是比较老的做法,现在建议使用isinstance(x, type) -- I like python! UliPad <>: http://code.google.com/p/ulipad/ meide < >: http://code.google.com/p/meide/ My Blog: http://www.donews.net/limodou
2008年01月15日 星期二 19:41
ÔÚ08-1-15£¬kun xu <coonxu在gmail.com> дµÀ£º > > Ò»¸ö±äÁ¿¿ÉÒÔ±»¸³ÓèÈκÎÀàÐ͵ÄÖµ£¬ÎÒÈçºÎÖªµÀµ±Ç°Õâ¸ö±äÁ¿ÊÇʲôÀàÐÍÄØ£¿ > > a = 11 > a = '11' > > ÈçºÎÖªµÀaµ±Ç°ÊÇʲôÀàÐÍ£¿ > <http://python.cn/mailman/listinfo/python-chinese> > a²»ÊDZäÁ¿¶øÊÇÕâ¸ö±äÁ¿µÄÃû³Æ, 11»òÕß'11'Õâ²ÅÊDZäÁ¿, ¾ÍÏñ×ÖµäÀïµÄkeyºÍvalueµÄ¹ØÏµÒ»Ñù, aÖ»ÊÇkey, ¶øÊµ¼ÊµÄ±äÁ¿ÊÇÕâ¸ö11»ò'11'µÄvalue. ÕⲻͬÓÚCÀïÃæµÄint a = 11»òÕßchar* a = '11', CÀïÃæµÄa¾ÍÊDZäÁ¿, ÒòΪ11»ò'11'¾Í´æ´¢ÓÚÄÚ´æaλÖÃ. -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20080115/9675fcba/attachment.htm
Zeuux © 2025
京ICP备05028076号