Python Forum
The "traceback" is here
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The "traceback" is here
#1
I have to extract all the numbers in the file and compute the sum of the numbers.

import re
sum=0
name=input('Enter name of file:')
file=open(name)
for lines in file:
    numbers=re.findall('[0-9]+')
    if len(numbers) == 0:
        continue
    for num in numbers:
        no=int(num)
        sum=sum+no
print(sum)
The traceback :

Error:
Traceback (most recent call last): File "F:/Python Programs/regular_ass.py", line 7, in <module> numbers=re.findall('[0-9]+') TypeError: findall() missing 1 required positional argument: 'string'
Can someone please explain me the traceback and why is it here?
Reply
#2
findall takes a pattern as a first arg, and a string as a second
https://docs.python.org/3/library/re.html#re.findall
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020