zoukankan      html  css  js  c++  java
  • 一个简单的python程序

    假设我们有这么一项任务:简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200. 

    import subprocess
    cmd="cmd.exe"
    begin=101
    end=200
    while begin<end:

        p=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,
                       stdin=subprocess.PIPE,
                       stderr=subprocess.PIPE)
        p.stdin.write("ping 192.168.1."+str(begin)+" ")

        p.stdin.close()
        p.wait()

        print "execution result: %s"%p.stdout.read()

    对比Java,Python的实现更为简洁,你编写的时间更快.你不需要写main函数,并且这个程序保存之后可以直接运行.另外,和Java一样,Python也是跨平台的.

  • 相关阅读:
    CI控制器
    php+mysql新无线级分类
    php函数引用
    java数据类型
    进制装换
    java环境
    node.js
    移动端或者网页端下拉加载
    yii DAO操作总结
    yii中find()指定条件
  • 原文地址:https://www.cnblogs.com/vickyyu/p/4090002.html
Copyright © 2011-2022 走看看