def _check_str_value(x):
    """If string has a space, wrap it in double quotes and remove/escape illegal characters"""
    if isinstance(x, str):
        # remove commas, and single quotation marks since loadarff cannot deal with it
        x = x.replace(",", ".").replace(chr(0x2018), "'").replace(chr(0x2019), "'")

        # put string in double quotes
        if " " in x:
            if x[0] in ('"', "'"):
                x = x[1:]
            if x[-1] in ('"', "'"):
                x = x[:len(x) - 1]
            x = '"' + x.replace('"', "\\\"") + '"'
    return str(x)
def _check_str_value ( x ) : if isinstance ( x , str ) : x = x . replace ( "," , "." ) . replace ( chr ( 0x2018 ) , "'" ) . replace ( chr ( 0x2019 ) , "'" ) if " " in x : if x [ 0 ] in ( '"' , "'" ) : x = x [ 1 : ] if x [ - 1 ] in ( '"' , "'" ) : x = x [ : len ( x ) - 1 ] x = '"' + x . replace ( '"' , "\\\"" ) + '"' return str ( x )
If string has a space, wrap it in double quotes and remove/escape illegal characters