Convert True/False value read from file to boolean

前端 未结 14 939

I\'m reading a True - False value from a file and I need to convert it to boolean. Currently it always converts it to True even if the value is set

14条回答
  •  情书的邮戳
    2020-12-07 18:51

    Using dicts to convert "True" in True:

    def str_to_bool(s: str):
        status = {"True": True,
                    "False": False}
        try:
            return status[s]
        except KeyError as e:
            #logging
    

提交回复
热议问题