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
    在写脚本的时候,遇到很多问题。主要还是逻辑思维还不太够清晰。经过一番改良后,更加加深了对语法的印象。

  • 相关阅读:
    逆向挑战赛Bob Doge 和 who is he
    [ACTF新生赛2020]rome
    [ACTF新生赛2020]usualCrypt
    MAZE
    $FFT/NTT/FWT$题单&简要题解
    普通型生成函数总结
    [BZOJ4817][SDOI2017]树点涂色:Link-Cut Tree+线段树
    [BZOJ3527][ZJOI2014]力:FFT
    长链剖分优化树形DP总结
    Dsu on Tree总结
  • 原文地址:https://www.cnblogs.com/glxsc/p/5136272.html
Copyright © 2011-2022 走看看