V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2013-03-22 17:13:26 +08:00 · 3197 次点击
    这是一个创建于 4058 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    1970-01-01 08:00:00 +08:00
    amxku
        1
    amxku  
    OP
       2013-03-22 17:33:25 +08:00
    amxku
        2
    amxku  
    OP
       2013-03-22 17:33:46 +08:00
    phuslu
        3
    phuslu  
       2013-03-22 17:40:04 +08:00
    return any(x in socket.gethostbyaddr(arg.strip())[0] for x in ['baidu','google','yahoo','msn'])
    sykp241095
        4
    sykp241095  
       2013-03-22 17:52:23 +08:00
    不用popen怎么都快。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   954 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:47 · PVG 02:47 · LAX 11:47 · JFK 14:47
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.