AttributeError: 'str' object has no attribute 'sub' Python code

15,050

re.sub is a function in the re module, not a method of a string.

import re
morning_agenda = re.sub('([0-9]+)\.([0-9]+)', r'\1:\2', morning_agenda)
Share:
15,050

Related videos on Youtube

user1737250
Author by

user1737250

Updated on July 11, 2022

Comments

  • user1737250
    user1737250 almost 2 years

    Getting this error trying to study for an upcoming final exam and need to understand why it isnt working. Here is the code.

    morning_agenda = "At 9.00AM the project team will assemble. The first topic will be fixing the bug in program product.py. We'll break for coffee at 10.30. Work will then continue on improving display.html until 12.30PM."
    
    print morning_agenda
    
    morning_agenda.sub('([0-9]+)\.([0-9]+)', r'\1:\2', morning_agenda)
    
    print morning_agenda