Python inport file with elements as int to list -
i want read int
, there pythonic way of doing this?
f = open('p059_cipher.txt', 'ru') holder = list((f.read().replace('"', '').split(','))) letters = list() number in holder: letters.append(int(number))
i'm trying guess input, might work:
from ast import literal_eval open('p059_cipher.txt') f: data = "[" + f.read() + "]" result = list(map(int, literal_eval(data))) # call list necessary if both # 1. explicitly need list # 2. you're running python3 # if you're in python2 or need iterate, ignore list call
this should take input like:
"1", "2", "3", "4", "12", "1003981890213"
and create
result == [1, 2, 3, 4, 12, 1003981890213]
Comments
Post a Comment