Malformed String ValueError ast.literal_eval() with String representation of Tuple

前端 未结 4 1356
自闭症患者
自闭症患者 2020-11-29 04:00

I\'m trying to read in a string representation of a Tuple from a file, and add the tuple to a list. Here\'s the relevant code.

raw_data = userfile.read().spl         


        
4条回答
  •  臣服心动
    2020-11-29 04:42

    Use eval() instead of ast.literal_eval() if the input is trusted (which it is in your case).

    raw_data = userfile.read().split('\n')
    for a in raw_data : 
        print a
        btc_history.append(eval(a))
    

    This works for me in Python 3.6.0

提交回复
热议问题