1

This example works properly to find and replace from a Jupyter cell:

all_labels = ['cat', 'dog'] 
!sed -i 's/num_classes: 90/num_classes: {len(all_labels)}/g' {FILE_PATH}

However this example with the same syntax produces an error:

record_path = '/path/to/data.record'
!sed -i 's/PATH_TO_BE_CONFIGURED\/mscoco_train\.record/{record_path}/g' {FILE_PATH}

I added two forward slashes to escape the backslash and period so my regex tester would recognize the sentence. The error I get is:

sed: -e expression #1, char 50: unknown option to `s'

Anyone know why I can pass a variable in the first example, but not in the second?

Austin
  • 6,921
  • 12
  • 73
  • 138
  • Don't think this is entirely a duplicate as that post mentions nothing about how to do this easily with python or jupyter shell assignment. – Austin Jun 01 '18 at 19:00

1 Answers1

1

I ended up needing to escape the variable too

import re
record_path = re.escape(record_path)
Austin
  • 6,921
  • 12
  • 73
  • 138