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


Python Path.exists方法代码示例

本文整理汇总了Python中Path.Path.exists方法的典型用法代码示例。如果您正苦于以下问题:Python Path.exists方法的具体用法?Python Path.exists怎么用?Python Path.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Path.Path的用法示例。


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

示例1: CMakeCache

# 需要导入模块: from Path import Path [as 别名]
# 或者: from Path.Path import exists [as 别名]
class CMakeCache( object ):
    """This class is used to read in and get programmatic access to the
    variables in a CMakeCache.txt file, manipulate them, and then write the
    cache back out."""

    def __init__( self, path=None ):
        self._cachefile = Path( path )
        _cachefile = str( self._cachefile )
        self._entries = {}
        if self._cachefile.exists():
            with open( _cachefile ) as c:
                entries = filter( None, map( lambda x: CacheEntry( x ),
                                             c.readlines() ) )
                entries = filter( lambda x: x.value() != None, entries )
                for i in entries:
                    self._entries[i.name()] = i

    def __contains__( self, thingy ):
        try:
            return thingy in self.names()
        except TypeError:
            return thingy in self._entries.values()

    def __iter__( self ):
        return self._entries

    def __nonzero__( self ):
        return len( self._entries ) > 0

    def __str__( self ):
        return os.linesep.join( map( lambda x: str( x ), self.entries() ) )

    def add( self, entry ):
        e = CacheEntry( entry )
        if e:
            if not e in self:
                self._entries[e.name()] = e
            else:
                sys.stderr.write( "Entry for '%s' is already in the cache.\n" % \
                                      e.name() )
        else:
            sys.stderr.write( "Could not create cache entry for '%s'\n" % e )

    def update( self, entry ):
        e = CacheEntry( entry )
        if e:
            self._entries[e.name()] = e
        else:
            sys.stderr.write( "Could not create cache entry for '%s'\n" % e )

    def names( self ):
        return self._entries.keys()

    def entries( self ):
        return self._entries.values()

    def get( self, name ):
        return self._entries[name]

    def cachefile( self ):
        return self._cachefile

    def refresh( self ):
        self.__init__( self._cachefile )

    def write( self, newfile = None ):
        if newfile == None:
            newfile = self._cachefile

        with open( newfile, 'w' ) as f:
            for e in self.entries():
                f.write( str( e ) + os.linesep )
开发者ID:ryutaro765,项目名称:Alembic,代码行数:74,代码来源:CMakeCache.py


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