I’m just learning python, and seem to be making a trivial mistake. With this code, the use of the constructor to Patterns gets and error.
” cit_ref = Patterns( patstring, 3)
TypeError: this constructor takes no arguments”
import re
class Patterns:
"""A simple struct to hold our regex """
def __init__(self, pat, bodynumArg=2):
self.pat = pat
self.bodynum = bodynumArg
self.reg = re.compile(self.pat, re.M+re.S)
patstring = r'<((us-)?references-cited)>(.*?)</\1>'
cit_ref = Patterns( patstring, 3)
You just need to indent your
__init__function so that it is underclass Patterns. Like this:In Python, indents do basically the same thing that brackets/braces do in other languages- they delimit code, so you have to be careful with your indentation.