Before doing any regex @keames,should first figure out what going on
Like using
@ivinjjunior if i just copy your code from post and run it.
There can be a extra first blank line there,if you copied all in without enter after your post sentence.
Like using
repr()
that i will show later.@ivinjjunior if i just copy your code from post and run it.
There can be a extra first blank line there,if you copied all in without enter after your post sentence.
with open('numbers.txt') as f: for line in f: line = line.strip() print(int(line))
Output:2105301
2106301
2108701
2108801
2108901
2109101
2109201
2109501
To see all use repr()
,here i just remove strip()
then will see \n
or any other problem that there can be with input file.with open('numbers.txt') as f: for line in f: line = line print(repr(line))
'2105301\n' '2106301\n' '2108701\n' '2108801\n' '2108901\n' '2109101\n' '2109201\n' '2109501'My guess is that you have blank line in file,then cant try this.
with open('numbers.txt') as f: for line in f: line = line.strip() if line != '': print(int(line))