推荐学习书目
› 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 · 4168 views
    This topic created in 4934 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   ·   Privacy   ·   Solana   ·   944 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 19:06 · PVG 03:06 · LAX 12:06 · JFK 15:06
    ♥ Do have faith in what you're doing.