Convert True/False value read from file to boolean

前端 未结 14 932

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 19:04

    You can do with json.

    In [124]: import json
    
    In [125]: json.loads('false')
    Out[125]: False
    
    In [126]: json.loads('true')
    Out[126]: True
    

提交回复
热议问题