zoukankan      html  css  js  c++  java
  • python 自动下载 moudle

    import sys,re,subprocess
    import os
    from subprocess import CalledProcessError
    
    new_set = set()
    ls = set()
    
    def dls():
        temp_set = set()
        a = subprocess.check_output("ls -R", shell=True)
        for line in a.split('
    '):
              str = re.sub(r'.py', r'', line)
              if  str.find('.')<0  and str!='
    ' :
                   temp_set.add(str)
                   print str
        return temp_set
       
    
    def dpip(new_set):
        ls = dls()
        for str in new_set-ls:
             str = str.replace('
    ','')
             with open('daicy.py', 'w') as f:
                         f.write('import '+str)
             try:
                  a = subprocess.check_call('python daicy.py', shell=True)
                  if a!=0:
                      command = 'pip  install  '+str
                      print command
                      subprocess.call(command, shell=True)
             except CalledProcessError, e:
                print 'except:', e
                command = 'pip  install  '+str
                print command
                os.system(command)
             finally:
                  pass
    
    a = subprocess.Popen('''find -name '*.py' | xargs grep -h -o -w  -s "^imports+([\_0-9a-zA-Z]+)|^froms+([\_0-9a-zA-Z]+)"''', shell=True,stdout=subprocess.PIPE)
    for line in a.stdout.readlines():
        line = line.replace('
    ','')
        new_set.add(re.sub(r'imports+|froms+', r'', line))
    
    
    dpip(new_set)
    


  • 相关阅读:
    基础练习 高精度加法
    基础练习 阶乘计算
    基础练习 闰年判断
    基础练习 01字串
    基础练习 字母图形
    基础练习 数列特征
    基础练习 杨辉三角形
    基础练习 特殊的数字
    基础练习 回文数
    Codeforces 417A Elimination
  • 原文地址:https://www.cnblogs.com/daichangya/p/12958501.html
Copyright © 2011-2022 走看看