OpenQuizz
Une application de gestion des contenus pédagogiques
Dict Class Reference
Inheritance diagram for Dict:
Collaboration diagram for Dict:

Public Member Functions

def __init__ (self, expr)
 
def postParse (self, instring, loc, tokenlist)
 
- Public Member Functions inherited from TokenConverter
def __init__ (self, expr, savelist=False)
 
- Public Member Functions inherited from ParseElementEnhance
def parseImpl (self, instring, loc, doActions=True)
 
def leaveWhitespace (self)
 
def ignore (self, other)
 
def streamline (self)
 
def checkRecursion (self, parseElementList)
 
def validate (self, validateTrace=[])
 
def __str__ (self)
 
- Public Member Functions inherited from ParserElement
def copy (self)
 
def setName (self, name)
 
def setResultsName (self, name, listAllMatches=False)
 
def setBreak (self, breakFlag=True)
 
def setParseAction (self, *fns, **kwargs)
 
def addParseAction (self, *fns, **kwargs)
 
def addCondition (self, *fns, **kwargs)
 
def setFailAction (self, fn)
 
def preParse (self, instring, loc)
 
def tryParse (self, instring, loc)
 
def canParseNext (self, instring, loc)
 
def parseString (self, instring, parseAll=False)
 
def scanString (self, instring, maxMatches=_MAX_INT, overlap=False)
 
def transformString (self, instring)
 
def searchString (self, instring, maxMatches=_MAX_INT)
 
def split (self, instring, maxsplit=_MAX_INT, includeSeparators=False)
 
def __add__ (self, other)
 
def __radd__ (self, other)
 
def __sub__ (self, other)
 
def __rsub__ (self, other)
 
def __mul__ (self, other)
 
def __rmul__ (self, other)
 
def __or__ (self, other)
 
def __ror__ (self, other)
 
def __xor__ (self, other)
 
def __rxor__ (self, other)
 
def __and__ (self, other)
 
def __rand__ (self, other)
 
def __invert__ (self)
 
def __call__ (self, name=None)
 
def suppress (self)
 
def setWhitespaceChars (self, chars)
 
def parseWithTabs (self)
 
def setDebugActions (self, startAction, successAction, exceptionAction)
 
def setDebug (self, flag=True)
 
def __repr__ (self)
 
def parseFile (self, file_or_filename, parseAll=False)
 
def __eq__ (self, other)
 
def __ne__ (self, other)
 
def __hash__ (self)
 
def __req__ (self, other)
 
def __rne__ (self, other)
 
def matches (self, testString, parseAll=True)
 
def runTests (self, tests, parseAll=True, comment='#', fullDump=True, printResults=True, failureTests=False)
 

Data Fields

 saveAsList
 
- Data Fields inherited from TokenConverter
 saveAsList
 
- Data Fields inherited from ParseElementEnhance
 expr
 
 strRepr
 
 mayIndexError
 
 mayReturnEmpty
 
 skipWhitespace
 
 saveAsList
 
 callPreparse
 
- Data Fields inherited from ParserElement
 parseAction
 
 failAction
 
 strRepr
 
 resultsName
 
 saveAsList
 
 skipWhitespace
 
 whiteChars
 
 copyDefaultWhiteChars
 
 mayReturnEmpty
 
 keepTabs
 
 ignoreExprs
 
 debug
 
 streamlined
 
 mayIndexError
 
 errmsg
 
 modalResults
 
 debugActions
 
 re
 
 callPreparse
 
 callDuringTry
 
 name
 

Additional Inherited Members

- Static Public Member Functions inherited from ParserElement
def setDefaultWhitespaceChars (chars)
 
def inlineLiteralsUsing (cls)
 
def resetCache ()
 
def enablePackrat (cache_size_limit=128)
 
- Static Public Attributes inherited from ParserElement
 DEFAULT_WHITE_CHARS
 
 verbose_stacktrace
 
 packrat_cache
 
 packrat_cache_lock
 
 packrat_cache_stats
 

Detailed Description

Converter to return a repetitive expression as a list, but also as a dictionary.
Each element can also be referenced using the first token in the expression as its key.
Useful for tabular report scraping when the first column can be used as a item key.

Example::
    data_word = Word(alphas)
    label = data_word + FollowedBy(':')
    attr_expr = Group(label + Suppress(':') + OneOrMore(data_word).setParseAction(' '.join))

    text = "shape: SQUARE posn: upper left color: light blue texture: burlap"
    attr_expr = (label + Suppress(':') + OneOrMore(data_word, stopOn=label).setParseAction(' '.join))
    
    # print attributes as plain groups
    print(OneOrMore(attr_expr).parseString(text).dump())
    
    # instead of OneOrMore(expr), parse using Dict(OneOrMore(Group(expr))) - Dict will auto-assign names
    result = Dict(OneOrMore(Group(attr_expr))).parseString(text)
    print(result.dump())
    
    # access named fields as dict entries, or output as dict
    print(result['shape'])        
    print(result.asDict())
prints::
    ['shape', 'SQUARE', 'posn', 'upper left', 'color', 'light blue', 'texture', 'burlap']

    [['shape', 'SQUARE'], ['posn', 'upper left'], ['color', 'light blue'], ['texture', 'burlap']]
    - color: light blue
    - posn: upper left
    - shape: SQUARE
    - texture: burlap
    SQUARE
    {'color': 'light blue', 'posn': 'upper left', 'texture': 'burlap', 'shape': 'SQUARE'}
See more examples at L{ParseResults} of accessing fields by results name.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  expr 
)

Reimplemented from ParserElement.

Member Function Documentation

◆ postParse()

def postParse (   self,
  instring,
  loc,
  tokenlist 
)

Reimplemented from ParserElement.

Field Documentation

◆ saveAsList

saveAsList

The documentation for this class was generated from the following file: