sub() missing 1 required positional argument: 'string'
Sub()缺少1个必需的位置参数:'string'
我们需要检查一下格式是否正确
def sub(pattern, repl, string, count=0, flags=0):
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a replacement string to be used."""
return _compile(pattern, flags).sub(repl, string, count)
(1)pattern:正则中的模式字符串;
(2)repl:替换的字符串(repl去替换pattern)可以是个函数;
(3)string:被处理(查找替换)的字符串;
(4)count:可选,替换的最大次数,必须>=0,该参数默认为0(所有的匹配都会被替换);
(5)flags:可选,编译时用的匹配模式(如忽略大小写、多行模式等),数字形式,默认为0。
出现ub() missing 1 required positional argument: 'string',就是缺少第三个变量