Parsing

Actually, Kivy has the parser package that helps in the CSS parsing. Even though it is not a complete parsing, it helps to parse instructions related to a framework. The recipe will show some that you could find useful in your context.

How to do it…

The parser package has eight classes, so we will work in Python to review all of them. Let's follow the next steps:

  1. Import the parser package.
    from kivy.parser import *
    
  2. Parse a color from a string.
    parse_color('#090909')
    
  3. Parse a string to a string.
    parse_string("(a,1,2)")a
    
  4. Parse a string to a boolean value.
    parse_bool("0")
    
  5. Parse a string to a list of two integers.
    parse_int2("12 54")
    
  6. Parse a string to a list of four floats.
    parse_float4('54 87.13 35 0.9')
    
  7. Parse a file name.
    parse_filename('e7.py') ...

Get Kivy Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.