(Python3, GPLv3) hierarchical levels like "1.2.3" or "A.IV.3.b"
Python
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
hlevel pylinted the code Mar 21, 2017
.gitignore new file : .gitignore Oct 12, 2013
README.md updated README.md Oct 16, 2013
pylint.rc added pylint.rc Oct 15, 2013
tests.py new directories structure : added hlevel/ Nov 27, 2013

README.md

hlevel

A (Python3, GPLv3) very simple library allowing to read/write and compare "Hierarchical Level" objects like "1.2.3", "A.IV.6.b" and so on.

Known formats :

    * Arabic numbers ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ...)
      negative, null or positive integers
      
    * capital letters ("A", "B", "C", "D", "E", ..., "X", "Y", "Z", "AZ", ...)
      positive integers, normally greater than zero (but see self.first_number)
    
    * lower case letters ("a", "b", "c", "d", "e", ..., "x", "y", "z" "az", ...)
      positive integers, normally greater than zero (but see self.first_number)
    
    * capital roman numbers ("I", "II", "III", ... "X", "XI", ... "MDCCCLIX", ...)
      positive integers, normally greater than zero (but see self.first_number)
    
    * lower case roman numbers ("i", "ii", "iii", ... "x", "xi", ... "mdccclix", ...)
      positive integers, normally greater than zero (but see self.first_number)
    
    * enclosed letters ( "①", "②", "③", "④", "⑤", ... "⑯", "⑰", "⑱", "⑲", "⑳" )
      only 20 numbers available (from 1 to 20)
      
    * Japanese numbers ( '〇', '一', '二', '三', ..., '九', "十", "十一", ... "百", ... "千", ... )
      null ('〇') or positive integers
    
    * superscript_symbols ("⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹", "¹⁰", ...)
      negative, null or positive integers

    * subscript_symbols ("₀", "₁", "₂", "₃", "₄", "₅", "₆", "₇", "₈", "₉", "₁₀", ...)
      negative, null or positive integers

    * fullwidth_symbols = ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", ...)
      negative, null or positive integers

    * lowercasegreek_symbols = ( "α", "β", "γ", "δ", "ε", "ζ", ..., "χ", "ψ", "ω", "αα", ... )
      positive integers, normally greater than zero (but see self.first_number)

    * capitalgreek_symbols = ( "Α", "Β", "Γ", "Δ", "Ε", "Ζ", ..., "Φ", "Χ", "Ψ", "Ω", "ΑΑ", ... )
      positive integers, normally greater than zero (but see self.first_number)

A basic example :

# separator = '.' ; suffix = ']', no prefix :
hl1 = HLevel( src="C.IX.3]",
              formatstr = ".A.I.1]" )

# separator = '.' ; suffix = ')', prefix = '('
hl2 = HLevel( src="(C.IX.3)",
              formatstr = ".(A.I.1)" )

# although the representations differ, we can compare these two objects :
print(hl1 == hl2)       # renvoie True

# representation :
print( hl1 )   # "C.IX.3]"
print( hl2 )   # "(C.IX.3)"

A slightly more complex example (HLevel is derived from list) :

hl1 = HLevel( formatstr = ".①.1.a)" )
hl1.append(13)
hl1.append(2)
hl1.append(3)
# hl1 ~ 13.2.3

hl2 = HLevel( src="<<②|99|z>>",
              formatstr = "|<<①|1|a>>" )
# hl2 ~ 2.99.26


print( hl1 > hl2 )  # True
print( hl1 )        # ⑬.2.c)
print( hl2 )        # <<②|99|z>>

If you want to find a HLevel substring :

hl = HLevel( formatstr = ".(I.I.I)" )
print( hl.findHLevelStringFromAString("aaa (IX.IV.MD) bbb" ))
# -> (True, 4, "(IX.IV.MD)")