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
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)
+ 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