当前位置: 首页>>代码示例>>Python>>正文


Python glob函数代码示例

本文整理汇总了Python中glob函数的典型用法代码示例。如果您正苦于以下问题:Python glob函数的具体用法?Python glob怎么用?Python glob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了glob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compileWithAsh

 def compileWithAsh(self, tests):
     start_time = datetime.today()
     #print("starting compile of %d tests at %s" % (len(tests),start_time))
     total=len(tests)
     if not pexpect:
           for test in tests:
               self.js_print('%d\tcompiling %s' % (total,test))
               self.compile_test(test)
               (testdir, ext) = splitext(test)
               if exists(testdir+".abc")==False:
                   print("ERROR abc files %s.abc not created" % (testdir))
                   self.ashErrors.append("abc files %s.abc not created" % (testdir))
               total -= 1;
     else:  #pexpect available
         child = pexpect.spawn("java -classpath %s macromedia.asc.embedding.Shell" % self.asc)
         child.logfile = None
         child.expect("\(ash\)")
         child.expect("\(ash\)")
 
         for test in tests:
             if self.debug:
                 print cmd
             else:
                 print "Compiling ", test
                 
             if test.endswith(self.abcasmExt):
                 self.compile_test(test)
             else:
                 arglist = self.parseArgStringToList(self.ascargs)
             
                 (dir, file) = split(test)
                 # look for .asc_args files to specify dir / file level compile args
                 arglist = self.loadAscArgs(arglist, dir, test)
                 
                 cmd = "asc -import %s " % (self.builtinabc)
                 for arg in arglist:
                     cmd += ' %s' % arg
                 
                 for p in self.parents(dir):
                     shell = join(p,"shell.as")
                     if isfile(shell):
                         cmd += " -in " + shell
                         break
                 (testdir, ext) = splitext(test)
                 deps = glob(join(testdir,"*.as"))
                 deps.sort()
                 for util in deps + glob(join(dir,"*Util.as")):
                     cmd += " -in %s" % util #no need to prepend \ to $ when using ash
                 cmd += " %s" % test
             
                 if exists(testdir+".abc"):
                     os.unlink(testdir+".abc")
                 child.sendline(cmd)
                 child.expect("\(ash\)")
                 if not exists(testdir+".abc"):
                     print("ERROR: abc file %s.abc not created, cmd used to compile: %s" % (testdir,cmd))
                     self.ashErrors.append("abc file %s.abc not created, cmd used to compile: %s" % (testdir,cmd))
                 total -= 1;
                 #print("%d remaining, %s" % (total,cmd))
     end_time = datetime.today()
开发者ID:FlowShift,项目名称:thane,代码行数:60,代码来源:runtestBase.py

示例2: generate_pipeline_hash

    def generate_pipeline_hash(self, inputs, dependencies=[], filenames=True):
        """
            Returns a hash representing this pipeline combined with its inputs
        """
        from .glob import glob

        hasher = md5()

        join = lambda it: (y for x in it for y in x)
        expanded_inputs = list(join([ glob(x) for x in inputs]))

        for inp in sorted(expanded_inputs):
            if filenames:
                u = str(os.path.getmtime(inp))
                hasher.update(u)
            else:
                hasher.update(inp)

        for dep in dependencies:
            # Update hasher for every file in dependencies
            for f in sorted(glob(dep)) if not os.path.isfile(dep) else [dep]:
                u = str(os.path.getmtime(f))
                hasher.update(u)

        return hasher.hexdigest()
开发者ID:potatolondon,项目名称:assetpipe,代码行数:25,代码来源:nodes.py

示例3: guess_language_from_files

def guess_language_from_files(path):
    from glob import glob

    with cd(path) as _:
        if len(glob('*.[ch]')) > 0:
            return 'c'
        elif len(glob('*.cxx') + glob('*.hxx')) > 0:
            return 'cxx'
        else:
            return None
开发者ID:csdms,项目名称:wmt-exe,代码行数:10,代码来源:bocca.py

示例4: CR_bounds

def CR_bounds():
    """
    Cramer-Rao bounds for signal to noise of 100 spectra 
    """
    filenames = glob("./gradient*npz") + glob("./Gradient_Spectra_elem/*npz") 
    for fn in filenames: 
        data = np.load(fn) 
        gradient_value = data["gradient_value"] 
        crb = 1.0/np.sqrt(np.sum(gradient_value**2 * 1.e4) ) 
        print crb, fn, crb 
开发者ID:mkness,项目名称:TheCannon,代码行数:10,代码来源:readin_gradient.py

示例5: build_incfiles

 def build_incfiles(self, as_file):
     files=[]
     (dir, file) = split(as_file)
     for p in self.parents(dir):
         shell = join(p,'shell'+self.sourceExt)
         if isfile(shell):
             files.append(shell)
     (testdir, ext) = splitext(as_file)
     if not self.eval:
         for util in glob(join(testdir,'*'+self.sourceExt)) + glob(join(dir,'*Util'+self.sourceExt)):
             files.append(string.replace(util, "$", "\$"))
     return files
开发者ID:FlowShift,项目名称:thane,代码行数:12,代码来源:runtestBase.py

示例6: can_folderise

def can_folderise(folder):
    """
    Check if corpus can be put into folders
    """
    import os
    from glob import glob
    if os.path.isfile(folder):
        return False
    fs = glob(os.path.join(folder, '*.txt'))
    if len(fs) > 1:
        if not any(os.path.isdir(x) for x in glob(os.path.join(folder, '*'))):
            return True
    return False
开发者ID:javelir,项目名称:corpkit,代码行数:13,代码来源:build.py

示例7: PDB_ITR

def PDB_ITR():
    PDB_DIRS = sorted(os.listdir("pdb"))
    for pdb_dir in PDB_DIRS:
        os.system("mkdir -p tmscores/{}".format(pdb_dir))
        FILES = glob(os.path.join("pdb", pdb_dir, "*.pdb"))
        for f_pdb in sorted(FILES):
            yield f_pdb
开发者ID:bestlab,项目名称:GREMLIN_RF,代码行数:7,代码来源:score_structures.py

示例8: make_movie_file

    def make_movie_file(self):
        """
        Create subdirectory based on casename, move all plot
        frame files to this directory, and generate
        an index.html for viewing the movie in a browser
        (as a sequence of PNG files).
        """
        # Make HTML movie in a subdirectory
        directory = self.casename
        if os.path.isdir(directory):
            shutil.rmtree(directory)   # rm -rf directory
        os.mkdir(directory)            # mkdir directory
        # mv frame_*.png directory
        for filename in glob('frame_*.png'):
            os.rename(filename, os.path.join(directory, filename))
        os.chdir(directory)        # cd directory
        self.plt.movie('frame_*.png', encoder='html',
                       output_file='index.html', fps=4)

        # Make other movie formats: Flash, Webm, Ogg, MP4
        codec2ext = dict(flv='flv', libx64='mp4', libvpx='webm',
                         libtheora='ogg')
        filespec = 'frame_%04d.png'
        movie_program = 'avconv'  # or 'ffmpeg'
        for codec in codec2ext:
            ext = codec2ext[codec]
            cmd = '%(movie_program)s -r %(fps)d -i %(filespec)s '\
                  '-vcodec %(codec)s movie.%(ext)s' % vars()
            os.system(cmd)
        os.chdir(os.pardir)  # move back to parent directory
开发者ID:Gullik,项目名称:INF5620,代码行数:30,代码来源:wave1D_dn_vc.py

示例9: output_module_html

def output_module_html(webpage_path):
    """Output an HTML page for each module"""

    icons_relpath = os.path.relpath(cellprofiler.icons.__path__[0])
    all_png_icons = glob(os.path.join(icons_relpath, "*.png"))
    icon_names = [os.path.basename(f)[:-4] for f in all_png_icons]

    help_text = """
<h2>Help for CellProfiler Modules</a></h2>
<ul>\n"""
    d = {}
    module_path = webpage_path
    if not (os.path.exists(module_path) and os.path.isdir(module_path)):
        try:
            os.mkdir(module_path)
        except IOError:
            raise ValueError("Could not create directory %s" % module_path)

    for module_name in sorted(cellprofiler.modules.get_module_names()):
        module = cellprofiler.modules.instantiate_module(module_name)
        location = os.path.split(
                module.create_settings.im_func.func_code.co_filename)[0]
        if location == cellprofiler.preferences.get_plugin_directory():
            continue
        if isinstance(module.category, (str, unicode)):
            module.category = [module.category]
        for category in module.category:
            if not d.has_key(category):
                d[category] = {}
            d[category][module_name] = module
        result = module.get_help()
        if result is None:
            continue
        result = result.replace('<body><h1>', '<body><h1>Module: ')

        # Replace refs to icons in memory with the relative path to the image dir (see above)
        result = re.sub("memory:", os.path.join("images", "").encode('string-escape'), result)

        # Check if a corresponding image exists for the module
        if module_name in icon_names:
            # Strip out end html tags so I can add more stuff
            result = result.replace('</body>', '').replace('</html>', '')

            # Include images specific to the module, relative to html files ('images' dir)
            LOCATION_MODULE_IMAGES = os.path.join('images', '%s.png' % module_name)
            result += '\n\n<div><p><img src="%s", width="50%%"></p></div>\n' % LOCATION_MODULE_IMAGES

            # Now end the help text
            result += '</body></html>'
        fd = open(os.path.join(module_path, "%s.html" % module_name), "w")
        fd.write(result)
        fd.close()
    for category in sorted(d.keys()):
        sub_d = d[category]
        help_text += "<li><b>%s</b><br><ul>\n" % category
        for module_name in sorted(sub_d.keys()):
            help_text += "<li><a href='%s.html'>%s</a></li>\n" % (module_name, module_name)
        help_text += "</ul></li>\n"
    help_text += "</ul>\n"
    return help_text
开发者ID:alisonkozol,项目名称:CellProfiler,代码行数:60,代码来源:manual.py

示例10: get_library_location

def get_library_location(package):
    # get abs path of a package in the library, rather than locally
    library_package_paths = glob(os.path.join(get_path('platlib'), '*'))
    sys.path = library_package_paths + sys.path
    package_path = get_loader(package).filename
    sys.path = sys.path[len(library_package_paths):]
    return package_path
开发者ID:clbarnes,项目名称:PyOpenWorm,代码行数:7,代码来源:post_install.py

示例11: processDatadir

def processDatadir(datadir, stu, bindir=None, dryrun=True):
	bestzip is None
	zips = glob(os.path.join(datadir, 'zips', '*tabblock*zip'))
	for zname in zips:
		if betterShapefileZip(zname, bestzip):
			bestzip = zname
	linksname = os.path.join(datadir, stu + '.links')
	mppb_name = os.path.join(datadir, stu + '.mppb')
	mask_name = os.path.join(datadir, stu + 'mask.png')
	mppbsm_name = os.path.join(datadir, stu + '_sm.mppb')
	masksm_name = os.path.join(datadir, stu + 'mask_sm.png')
	args1 = []
	if not os.path.exists(linksname):
		args1 += ['--links', linksname]
	if not os.path.exists(mppb_name):
		args1 += ['--rast', mppb_name, '--mask', mask_name,
			'--boundx', '1920', '--boundy', '1080']
	if args1:
		command = makeCommand(args1, bindir)
		if dryrun:
			print ' '.join(command)
		else:
			subprocess.Popen(command, shell=False, stdin=None)
	if not os.path.exists(mppbsm_name):
		args2 = ['--rast', mppbsm_name, '--mask', masksm_name,
			'--boundx', '640', '--boundy', '480', bestzip]
开发者ID:alanlujan91,项目名称:redistricter,代码行数:26,代码来源:shapefile.py

示例12: import_all_from_folder

def import_all_from_folder(path, excludes=[]):
  import os
  import sys
  from importlib import import_module
  from glob import glob

  modules = {}
  base_path = os.path.dirname(path)

  if not os.path.exists(base_path):
    raise ImportError("Cannot import modules from %s. Path does not exist." % base_path)

  add_path = base_path not in sys.path
    
  if add_path:
    sys.path.append(base_path)

  for file_path in glob('%s/*.py' % base_path):
    dir_name, file_name = os.path.split(file_path)
    module_name = file_name[:-3]
    modules[module_name] = import_module(module_name)

  if add_path:
    sys.path.remove(base_path)

  return modules
开发者ID:countach74,项目名称:frame,代码行数:26,代码来源:util.py

示例13: get_serials_info

def get_serials_info():
    """."""
    serials_info = {'ports': []}
    for port, desc, hwid in comports():
        if port:
            serials_info['ports'].append(port)
            info = {'port': port, 'description': desc, 'hwid': hwid}

            vid = ''
            pid = ''
            if hwid:
                hwid_infos = hwid.split()
                for hwid_info in hwid_infos:
                    if hwid_info.startswith('VID') and '=' in hwid_info:
                        vid_pid = hwid_info.split('=')[-1]
                        if ':' in vid_pid:
                            vid, pid = vid_pid.split(':')
                            vid = '0x' + vid.strip()
                            pid = '0x' + pid.strip()
                        break
            info['vid'] = vid
            info['pid'] = pid
            serials_info[port] = info

    os_name = sys_info.get_os_name()
    if not serials_info['ports'] and os_name == 'osx':
        for port in glob('/dev/tty.*'):
            serials_info['ports'].append(port)
            info = {'port': port, 'description': '', 'hwid': ''}
            info['vid'] = ''
            info['pid'] = ''
            serials_info[port] = info
    return serials_info
开发者ID:Robot-Will,项目名称:Stino,代码行数:33,代码来源:serial_port.py

示例14: step2

def step2():

    fraclist = np.array([1,0.2,0.02,0.005,0.4,2.5])
   
    for p in range(6):
    
        basename = 'NGC_891_P{}'.format(p+1)
       
        for z in range(fraclist.size):
            name = glob('{}*_Z{:04}.dat'.format(basename,int(fraclist[z]*1000)))[0]
            print name
            try:
                tmp[z] = np.loadtxt(name)
            except UnboundLocalError:
                data = np.loadtxt(name)
                tmp = np.zeros((fraclist.size,data.shape[0],data.shape[1]))
                tmp[z] = data

        bdx = np.argmin(tmp[:,:,15],axis=0)
        h = open(name,'r')
        head = h.readlines()[4]
        outname = '{}_fit.dat'.format(name.split('_Z')[0])
        f = open(outname,'w')
        f.write('# Generated on {}\n'.format(time.asctime()))
        f.write(head)
        for i in range(tmp.shape[1]):
            tmp[bdx[i],i,19] = fraclist[bdx[i]]
            f.write(str('{:11n}'+12*'{:13.3e}'+'{:7.2f}{:12.3f}'+4*'{:12.3e}'+'{:10.3f}'+'\n').format(*tmp[bdx[i],i,:]))
            
        f.close()
        h.close()
        del tmp

    return
开发者ID:eigenbrot,项目名称:snakes,代码行数:34,代码来源:bin_script.py

示例15: clean_flist

def clean_flist(raw_flist,s=False,lc=False):
    if not raw_flist:
        if (s or STRICT):
            raise Exception, "No file argument provided."
        else:
            perror("No file argument provided.")
            err("No file argument provided.")

    if type(raw_flist) != type(list()):
        raw_flist = [raw_flist]

    full_flist = []
    clean_list = []

    for f in raw_flist:
        full_flist.extend(glob(expand(f)))

    for entry in full_flist:
        valid = validate_path(entry)
        if exists(entry) and valid:
            clean_list.append(entry)
        elif not valid:
            warning("Invalid path: [%s] - skipping" % entry)
        else:
            warning("[%s] does not exist - skipping" % entry)

    if not clean_list:
        if (s or STRICT):
            raise Exception,"No such file or directory: %s" % raw_flist 
        else:
            warn("No such file or directory: [%s]" % raw_flist)

    return clean_list
开发者ID:djw8605,项目名称:condor_log_analyze,代码行数:33,代码来源:shex.py


注:本文中的glob函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。