字符串比较问题

41 views
Skip to first unread message

Jingle

unread,
Apr 17, 2009, 4:23:10 AM4/17/09
to bp...@googlegroups.com

目前正在学习python,版本为3.0.1。今天遇到一个问题,主要代码如下:

try:                              

            fsock = open(filename, "rb", 0)

            try:                          

                fsock.seek(-128, 2)       

                tagdata = fsock.read(128) 

            finally:                      

                fsock.close()             

            if tagdata[:3] == "TAG":

                。。。

        except IOError:                   

            pass

 

问题出在红色那行代码上,调试发现tagdata[:3]的值为b’TAG’,使用type检测发现其类型为bytes

”TAG”str,这个没有疑问。于是使用str函数将其转换为str类型,并赋值于一个新的变量temp

使用type检测发现类型已经没有问题了,但是使用print后发现,值又变为b’TAG’。郁闷中。。。

 

向各位大侠请教了!

Reply all
Reply to author
Forward
0 new messages