`
yy_gy
  • 浏览: 33711 次
  • 性别: Icon_minigender_2
社区版块
存档分类
最新评论

Google python copyspecial.py(python 2.7)

阅读更多
#!/usr/bin/python

import sys
import re
import os
import shutil
import commands
import zipfile

"""Copy Special exercise
"""

# +++your code here+++
# Write functions and modify main() to call them

def get_specials(dir):
  com='ls '+ dir
  status,output=commands.getstatusoutput(com)
  specials=[]
  for special in output.split():
    if re.findall(r'__(\w+)__',special):
      specials.append(special)
  return specials

def to_dir(dir,srcs):
  if not os.path.exists(dir):
    os.mkdir(dir)
  for src in srcs:
    shutil.copy(src,dir)

#s1:
def to_zip(zf,srcs):
  f=zipfile.ZipFile(zf,'w')
  for src in srcs:
    f.write(src)
  f.close()

#s2
def to_zip(zf,srcs):
 
  com='zip '+ zf +' '+' '.join(srcs)
  print com
  status,output=commands.getstatusoutput(com)
  if not status:
    print 'zip successed!'

def main():
  # This basic command line argument parsing code is provided.
  # Add code to call your functions below.

  # Make a list of command line arguments, omitting the [0] element
  # which is the script itself.
  args = sys.argv[1:]
  if not args:
    print "usage: [--todir dir][--tozip zipfile] dir [dir ...]";
    sys.exit(1)

  # todir and tozip are either set from command line
  # or left as the empty string.
  # The args array is left just containing the dirs.
  todir = ''
  if args[0] == '--todir':
    todir = args[1]
    del args[0:2]

  tozip = ''
  if args[0] == '--tozip':
    tozip = args[1]
    del args[0:2]

  if len(args) == 0:
    print "error: must specify one or more dirs"
    sys.exit(1)
 
  specials=get_specials(args[0])
  if todir:
    to_dir(todir,specials)
  if tozip:
    to_zip(tozip,specials)
 
if __name__ == "__main__":
  main()
分享到:
评论

相关推荐

    get-pip2.7.py

    pip安装,用于已有python2.7,但没有pip的情况下,下载后直接python get-pip2.7.py即可自动安装pip

    python2.7中所用的get-pip.py文件+安装方法

    Python是世界上最受欢迎的编程语言之一,特别是在数据科学、机器学习和Web开发领域。在Python的生态系统中,`pip`是一个至关...通过下载和使用`get-pip.py`,你可以确保在Python 2.7环境中也能享受到`pip`带来的便利。

    python2.7.xWindows32位和64位.zip

    Python 2.7.x是Python编程语言的一个历史悠久的版本,主要在Windows平台上广泛使用。这个压缩包包含了Python 2.7.x的32位和64位安装程序,分别是"python-2.7_32.15.msi"和"python-2.7.13.amd64.msi"。 1. **Python ...

    python learning.py

    python learning.py,非常适合用于学习Python的小伙伴~

    Python 删除.py文件

    Python 删除.py文件Python 删除.py文件Python 删除.py文件

    MySQL-python-1.2.3.win32-py2.7 MySQL-python-1.2.3.win-amd64-py2.7

    这个压缩包包含了两个版本的MySQL-python安装程序:一个适用于32位系统(MySQL-python-1.2.3.win32-py2.7.exe),另一个适用于64位系统(MySQL-python-1.2.3.win-amd64-py2.7.exe)。这两个文件都是为Python 2.7版本...

    python官方2.7.amd64版本msi安装包

    Python 2.7是Python编程语言的一个重要版本,特别是在它发布的时候,它是广泛使用的版本之一。这个AMD64.msi安装包是专为64位Windows操作系统设计的,确保在这些系统上无缝运行Python解释器及其相关的库和工具。...

    Python-2.7.x-win64-开发扩展包

    收集了很久的Window64位Python扩展包,是python的开发必备,列表如下,pycrypto-2.6.win64-py2.7\pywin32-216.win64-py2.7\PyYAML-3.10.win64-py2.7\pyzmq-2.1.11.win64-py2.7\MySQL-python-1.2.3.win64-py2.7\...

    python安装32位的 PIL-1.1.7.win32-py2.7.exe

    标题中的"PIL-1.1.7.win32-py2.7.exe"是指Python Imaging Library(PIL)的一个特定版本,适用于32位Windows操作系统,并且与Python 2.7版本兼容。PIL是Python中用于图像处理的库,提供了丰富的图像处理功能,包括...

    pandas-0.10.1.win32-py2.7.exe

    pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-py2.7.exe pandas-0.10.1.win32-...

    pandas-0.10.0.win32-py2.7.exe

    pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-py2.7.exe pandas-0.10.0.win32-...

    python ipin.py

    python ipin.py

    python-dateutil-2.2.win32-py2.7.exe

    python-dateutil-2.2.win32-py2.7.exe,python-dateutil-2.2.win32-py2.7.exe

    libpython2.7.so.1

    标题中的"libpython2.7.so.1"是一个动态链接库文件,它是Python 2.7版本的核心库在Linux系统中的实现。动态链接库(Dynamic Link Library)是Linux系统中的一种共享对象,允许多个程序同时使用同一份代码,节省内存...

    VCForPython27.msi

    【VCForPython27.msi】是微软Visual C++ for Python 2.7的安装程序,它是Python 2.7版本的一个重要组件。这个安装包主要用于解决Python在运行时依赖的C++编译器库问题,特别是对于那些使用了C扩展模块的Python库,如...

    scipy-0.16.1-win32-superpack-python2.7.exe

    scipy-0.16.1-win32-superpack-python2.7.exe 适合python2.7 直接点击运行安装即可。

    python-2.7.rar

    Python 2.7是Python编程语言的一个重要版本,它在2010年发布,并在之后的几年里成为了许多开发者的基础工具。这个压缩包“python-2.7.rar”包含了Python 2.7的安装文件“python-2.7.msi”,这允许用户在他们的计算机...

    py2exe-0.6.9.win32-py2.7.zip

    python转exe工具 -- python2.7版本的py2exe软件,可以将python转化为exe可执行文件。 py2exe是一个将python脚本转换成windows上的可独立执行的可执行程序(*.exe)的工具,这样,你就可以不用装python而在windows...

    Python2.7.13150和pyinstaller-develop.zip

    Python 2.7.13150 是 Python 语言的一个特定版本,发布于2016年,是Python 2.x系列中的一个重要版本。它包含了许多改进和修复,为开发者提供了更稳定和高效的编程环境。这个版本在当时是Python 2的最新更新,但请...

    numpy-1.9.1-win32-superpack-python2.7

    《numpy-1.9.1-win32-superpack-python2.7:Python科学计算的基石》 在Python的世界里,numpy是不可或缺的基石,尤其对于进行科学计算的开发者而言,它的重要性不言而喻。这个名为“numpy-1.9.1-win32-superpack-...

Global site tag (gtag.js) - Google Analytics