2006年09月01日 星期五 15:39
±¾ÈËʹÓà struct.unpack('20s20s20s20s',data) ´ÓÎļþÖжÁȡһ¸ö´®½á¹ûºóÃæÈ´ÓкܶàÎÒ²»ÏëÒªµÄ¶«Î÷£¬²»ÖªµÀÈçºÎ´¦Àí²ÅÄÜÈ¥µôÕâЩ·½¿ò£¬Çë½Ì¸ßÊÖ¡£¡£¡£
ÎҵĴúÂëÊÇ£º
from struct import *
data=fp.read(size)
email,name,connect,address=unpack('20s20s20s20s',data)
ConnectList.append({'Email':email,'name':name,'connect':connect,'Address':address})
for item in ConnectList:
print '%(Email)20s%(name)20s%(connect)20s%(Address)20s\n'%item
´òÓ¡½á¹ûÈçÏ£º
xtrgm345在163.com¡õ¡õ¡õ¡õ¡õ¡õ¡õxtrgm¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ21374¡õ¡õ¡õ¡õ¡õ¡õxtu¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ
xtrgm6在163.com¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ129381384¡õ¡õ¡õ¡õ¡õ¡õxt¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õaadlka¡õ¡õ¡õ¡õ¡õ¡õ
Çë½ÌÈçºÎ°ÑÆäÖеķ½¿òÈ¥µô£¬È¥²»ÌáҲû¹ØÏµ£¬¸æËßÎÒΪʲô»áÓÐÕâÑù·½¿ò
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20060901/3a177ad6/attachment.html
2006年09月01日 星期五 17:01
也许是\0吧,这不是C,\0也可以作为字符串里的字符,你得自己把后面的\0截掉... 在 06-9-1,重山<xtrgm623 at 163.com> 写道: > > 本人使用 struct.unpack('20s20s20s20s',data) > 从文件中读取一个串结果后面却有很多我不想要的东西,不知道如何处理才能去掉这些方框,请教高手。。。 > > > > 我的代码是: > > from struct import * > > > data=fp.read(size) > email,name,connect,address=unpack('20s20s20s20s',data) > > ConnectList.append({'Email':email,'name':name,'connect':connect,'Address':address}) > for item in ConnectList: > print > '%(Email)20s%(name)20s%(connect)20s%(Address)20s\n'%item > > > 打印结果如下: > xtrgm345 at 163.com□□□□□□□xtrgm□□□□□□□□21374□□□□□□xtu□□□□□□□□ > xtrgm6 at 163.com□□□□□□□□129381384□□□□□□xt□□□□□□□□aadlka□□□□□□ > > > 请教如何把其中的方框去掉,去不提也没关系,告诉我为什么会有这样方框 > > > > > > > 买 这 些 让 女 友 很 兴 奋 ( 图 ) > 真 会 过 日 子 ! 一 个 月 收 入 5800 漂 亮 MM 的 感 性 生 活 ( 组 图 ) > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to > python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request at lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese >
2006年09月03日 星期日 12:31
ȷʵÊÇ¡¡ASCII¡¡µÄ '\0' ×Ö·û£¬ÎÒÓÃ:
text.replace('\0','')
°ÑÕâЩ·½¿ò¶¼È¥µôÁË£¬ÕæµÄÊ®·Ö¸ÐлÁË£¡
-----ÔʼÓʼþ-----
·¢¼þÈË:"helium"
·¢ËÍʱ¼ä:2006-09-01 17:01:29
ÊÕ¼þÈË:python-chinese在lists.python.cn
³ËÍ:(ÎÞ)
Ö÷Ìâ:Re: [python-chinese]Ò»¸öÓÐ¹Ø pack ¶ÁÎļþµÄÎÊÌâ
Ò²ÐíÊÇ\0°É£¬Õâ²»ÊÇC£¬\0Ò²¿ÉÒÔ×÷Ϊ×Ö·û´®ÀïµÄ×Ö·û£¬ÄãµÃ×Ô¼º°ÑºóÃæµÄ\0½Øµô...
ÔÚ 06-9-1£¬ÖØÉ½<xtrgm623在163.com> дµÀ¡Ã
>
> ±¾ÈËʹÓà struct.unpack('20s20s20s20s',data)
> ´ÓÎļþÖжÁȡһ¸ö´®½á¹ûºóÃæÈ´ÓкܶàÎÒ²»ÏëÒªµÄ¶«Î÷£¬²»ÖªµÀÈçºÎ´¦Àí²ÅÄÜÈ¥µôÕâЩ·½¿ò£¬Çë½Ì¸ßÊÖ¡£¡£¡£
>
>
>
> ÎҵĴúÂëÊÇ¡Ã
>
> from struct import *
>
>
> data=fp.read(size)
> email,name,connect,address=unpack('20s20s20s20s',data)
>
> ConnectList.append({'Email':email,'name':name,'connect':connect,'Address':address})
> for item in ConnectList:
> print
> '%(Email)20s%(name)20s%(connect)20s%(Address)20s\n'%item
>
>
> ´òÓ¡½á¹ûÈçÏ¡Ã
> xtrgm345在163.com¡õ¡õ¡õ¡õ¡õ¡õ¡õxtrgm¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ21374¡õ¡õ¡õ¡õ¡õ¡õxtu¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ
> xtrgm6在163.com¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õ129381384¡õ¡õ¡õ¡õ¡õ¡õxt¡õ¡õ¡õ¡õ¡õ¡õ¡õ¡õaadlka¡õ¡õ¡õ¡õ¡õ¡õ
>
>
> Çë½ÌÈçºÎ°ÑÆäÖеķ½¿òÈ¥µô£¬È¥²»ÌáҲû¹ØÏµ£¬¸æËßÎÒΪʲô»áÓÐÕâÑù·½¿ò
>
>
>
>
>
>
> Âò Õâ Щ Èà Ů ÓÑ ºÜ ÐË ·Ü ( ͼ )
> Õæ »á ¹ý ÈÕ ×Ó ! Ò» ¸ö Ô ÊÕ Èë 5800 Ư ÁÁ MM µÄ ¸Ð ÐÔ Éú »î ( ×é ͼ )
> _______________________________________________
> 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
>
_______________________________________________
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/20060903/fcccb87d/attachment.htm
Zeuux © 2025
京ICP备05028076号