0

reading ints from file in python

i have a file include ints and strs.so i just want to read ints. the file is like this: *abcd*12*abcd*27747*abcd*2

2nd Jun 2018, 10:58 AM
mohamadjavad
mohamadjavad - avatar
2 Réponses
+ 1
u could try this as well: with open('c.txt','r') as fr: z = [i for i in fr.read() if i.isdigit()] print(z)
3rd Jun 2018, 4:27 AM
Flash
+ 1
🌛DT🌜 ur code has two errors 1) a valueerror, since split() takes a separator as arg, which by default is ‘ ‘ not an empty(‘’) separator 2)even if u had used someFile.read(), u would’ve got another valueerror, because u were trying to cast string to int. p.s. make sure ur code works before u help someone thanks
3rd Jun 2018, 4:41 AM
Flash