Note that I cannot modify s
on creation and I am ideally looking for a method via ast
The following expression
import ast
s = 'func(arg="\\\\my\\network\\drive")'
ast.parse(s).body[0].value.keywords[0].value.s
will return
'\\my\network\\drive'
Is there anyway to get around this without manually modifying s
as follows
ast.parse(s.replace('\\', '\\\\')).body[0].value.keywords[0].value.s
The expected output is:
"\\\\my\\network\\drive"