Reputation: 3256
I have following code:
test = 'abc {\"hello\":\"world\"}'
test1 = test[test.find('{'):]
print(test1)
I am looking to get back: {\"hello\":\"world\"}
But above code is removing escape characters, is there a way to keep these escape characters in the substring?
Upvotes: 0
Views: 38
Reputation: 3256
Found the solution, this might help someone:
test = r'abc {\"hello\":\"world\"}'
test1 = test[test.find('{'):]
print(test1)
Upvotes: 1
Reputation: 1182
Add an extra "\" before each "\"
test = 'abc {\\"hello\\":\\"world\\"}'
test1 = test[test.find('{'):]
print(test1)
the output is now {\"hello\":\"world\"}
Upvotes: 0