Parsing strings according to python formats