推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
simple2025
0D
V2EX  ›  Python

关于 Python 的一个问题

  •  
  •   simple2025 · Feb 26, 2019 · 2671 views
    This topic created in 2773 days ago, the information mentioned may be changed or developed.
    a='ÿþU\x00S\x00E\x00 \x00[\x00P\x00h\x00o\x00n\x00e\x00D\x00a\x00t\x00a\x00]\x00\n'
    print(a)
    index=a.find('PhoneData')
    
    

    为什么 index==-1 呢?有点看不懂呀?
    有人指点下吗?

    Supplement 1  ·  Feb 26, 2019
    还是我文件编码识别错了。。
    7 replies  •  2019-02-26 14:13:04 +08:00
    40huo
        1
    40huo  
       Feb 26, 2019   ❤️ 1
    -1 就是没找到
    ysc3839
        2
    ysc3839  
       Feb 26, 2019   ❤️ 1
    你是对 find 有误解吗? find 寻找的是连续的整段字符串,中间不能包括别的字符的。
    Vegetable
        3
    Vegetable  
       Feb 26, 2019   ❤️ 1
    `\00`相当于 ascii 码的 NUL(null),空字符,虽然不可见但是他是存在的.
    所以你的 PhoneData 之间有别的字符.和你找的不一样.
    RyougiShiki
        5
    RyougiShiki  
       Feb 26, 2019   ❤️ 1
    a=u'ÿþU\x00S\x00E\x00 \x00[\x00P\x00h\x00o\x00n\x00e\x00D\x00a\x00t\x00a\x00]\x00\n'
    print(a) # ÿþUSE [PhoneData]
    est
        6
    est  
       Feb 26, 2019   ❤️ 2
    a='ÿþU\x00S\x00E\x00 \x00[\x00P\x00h\x00o\x00n\x00e\x00D\x00a\x00t\x00a\x00]\x00\n'
    b=a.encode('latin1').decode('utf16', 'ignore')
    b.find('PhoneData')
    SleipniR
        7
    SleipniR  
       Feb 26, 2019   ❤️ 1
    In [29]: u"\x00P\x00h\x00o\x00n\x00e\x00D\x00a\x00t\x00a\x00" == u"PhoneData"
    Out[29]: False
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2481 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 14:57 · PVG 22:57 · LAX 07:57 · JFK 10:57
    ♥ Do have faith in what you're doing.