V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
maochihuangguama
V2EX  ›  Python

小白求教

  •  
  •   maochihuangguama · Jul 5, 2016 · 3055 views
    This topic created in 3583 days ago, the information mentioned may be changed or developed.

    coding:utf-8

    sensitivewords=['长者','蛤'] keyword=raw_input('请输入\n') if keyword not in sensitivewords: print 'ok'

    输出结果在交互模式和以.py 文件打开形式下不一致,交互模式下是正确的,不知道为什么? 不会传图。。不好意思,大家帮忙看看

    Supplement 1  ·  Jul 5, 2016
    #coding:utf-8
    wordlist=['你好','世界']
    keyword=raw_input('请输入:\n')
    if keyword not in wordlist:
    print 'OK'
    Supplement 2  ·  Jul 5, 2016
    print 那一行前面有 4 个空格的… V2EX 自动排版了
    6 replies    2016-07-05 10:44:58 +08:00
    AZLisme
        1
    AZLisme  
       Jul 5, 2016
    你这神一样的贴代码方式。
    目测是编码的问题,
    代码第一行加上 `# -*- coding:utf-8 -*-` 试试
    chunqiuyiyu
        2
    chunqiuyiyu  
       Jul 5, 2016
    排一下版,别伤害我的眼睛
    maochihuangguama
        3
    maochihuangguama  
    OP
       Jul 5, 2016 via Android
    @AZLisme 上传好了才发现…第一次发,抱歉。

    交互模式下能够正常匹配,但是以文件打开时不管输入什么词语都会 print 'OK'
    v3aqb
        4
    v3aqb  
       Jul 5, 2016
    sensitivewords = [u'长者', u'蛤'], keyword = keyword.decode('cp936')
    maochihuangguama
        5
    maochihuangguama  
    OP
       Jul 5, 2016 via Android
    @v3aqb 谢谢!我试试…列表里的随便取的,感觉这个有人看一点😁
    toono
        6
    toono  
       Jul 5, 2016
    啊,我的眼睛
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   990 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:47 · PVG 03:47 · LAX 12:47 · JFK 15:47
    ♥ Do have faith in what you're doing.