zoukankan      html  css  js  c++  java
  • 第一次写的脚本

    #!/usr/bin/env python
    # encoding:utf-8
    #author gxcc 2016

    import os,sys,time
    install_dir = "/soft/"   #定义存放安装包的目录
    tar_dir ="/softdoc/"     #定义解压安装包存放的目录
    os.chdir(install_dir)    #切换至/soft

    print "33[32m++++++++welcome to use python install script+++++++33[0m"
    time.sleep(1)

    if os.path.exists(tar_dir):
    print "the doc %s exist" % tar_dir
    else:
    os.mkdir(tar_dir)
    print "the doc %s create sucessful" % tar_dir

    install_file = os.listdir(install_dir)   #将安装目录下的软件包以列表的形式显示

    print "=================================================================="
    for i in range(len(install_file)):
    print i,install_file[i]
    print "=================================================================="

    while True:
    j = len(install_file)   #列表的长度
    choice = raw_input("pleas enter an number:")

    if not choice.isdigit():    #定义是否输入是纯数字
    print "please enter interger"
    break

        if int(choice) > j-1:    #列表的索引最大值比长度少1
    print "the index out of range"
    break

    else:
    print "Begin to exce the file"
    time.sleep(1)
    tar_cmd = "tar zxvf %s -C %s" % (install_file[int(choice)],tar_dir)
    os.system(tar_cmd)
    print "It's ok"
    break
    在写脚本的时候,遇到很多问题。主要还是逻辑思维还不太够清晰。经过一番改良后,更加加深了对语法的印象。

  • 相关阅读:
    算法提高 约数个数
    算法提高 第二大整数
    算法提高 逆序排列
    算法提高 c++_ch02_01
    算法提高 日期计算
    程序员教你设置密码
    fzu 2184 逆序数还原
    fzu 2146 Easy Game
    算法训练 区间k大数查询
    算法训练 最大最小公倍数
  • 原文地址:https://www.cnblogs.com/glxsc/p/5136272.html
Copyright © 2011-2022 走看看