0

Here is a string:

string='''assert self.kwargs.get('scan_type') in scan_types
        assert self.kwargs.get('quantity_type') in quantity_type_list
        assert self.kwargs.get('scheduled') in [True, False]
        assert self.kwargs.get('clear_scans') in [True, False]
        assert self.kwargs.get('run') in [True, False]'''

I would like to change all occurrences of:

self.kwargs.get('arg')

with:

self.arg

I've worked out that the regex pattern to match this type of phrase is:

pattern = self.kwargs.get\('(.*)'\)

How can I use this pattern to replace all instances of self.kwargs.get('arg') to self.arg?

I've tried using re.sub but I'm not sure how to use the output of the pattern (i.e. the contents of the capture group) within the replacement clause of re.sub.

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106

0 Answers0