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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -