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
amxku
V2EX  ›  Python

这段代码,还能怎么优化效率,求建议

  •  
  •   amxku · Mar 22, 2013 · 3833 views
    This topic created in 4785 days ago, the information mentioned may be changed or developed.
    def checkIpName(arg):
    cmd = 'nslookup %s' % arg.strip()
    handle = Popen(cmd, stdout = PIPE, stderr = PIPE, shell = True).stdout
    re_handle = handle.read()
    handle.close()

    # name 关键词
    botkey = ['baidu','google','yahoo','msn']

    if re.search('Name',re_handle):
    for bk in botkey:
    checkkey = re.search(bk,re_handle)
    if checkkey:
    print "%s-%s\n" % (arg.strip(),bk)
    break
    4 replies    1970-01-01 08:00:00 +08:00
    amxku
        1
    amxku  
    OP
       Mar 22, 2013
    amxku
        2
    amxku  
    OP
       Mar 22, 2013
    phuslu
        3
    phuslu  
       Mar 22, 2013
    return any(x in socket.gethostbyaddr(arg.strip())[0] for x in ['baidu','google','yahoo','msn'])
    sykp241095
        4
    sykp241095  
       Mar 22, 2013
    不用popen怎么都快。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1110 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 18:22 · PVG 02:22 · LAX 11:22 · JFK 14:22
    ♥ Do have faith in what you're doing.