Giter Site home page Giter Site logo

compactlist's Introduction

CompactList

A small python library to compact lists of textual items containing numerical sequences, into an abbreviated format, such as foo.[0001-0100].jpg or foo.[1-5,8-10].jpg.

Subclass CompactList, overriding pattern with a regex that matches the items in the list. Override _getNumber() to return the numerical index portion of the item's text, and override _getGeneric() to return the remainder of the item's text, with "{0}" substituted for the index portion.

For example:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import compactlist
>>> class FileSequenceList(compactlist.CompactList):
...     pattern = re.compile(r'^(?P<name>\D+\.?)(?P<frame>\d+)(?P<ext>\.\w+)$')
...     def _getNumber(self, m):
...         return m['frame']
...     def _getGeneric(self, m):
...         return m['name']+'{0}'+m['ext']
...
>>> f = FileSequenceList(os.listdir("tmp"))
>>> for s in f.itercompact():
...   print s
...
singleton.0001.exr
otherseq.[0001-0100].exr
foo.txt
somefilesequence.[1-4,6,8-49,60-100].exr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.