Convert regular Python string to raw string

Convert regular Python string to raw string

i believe what youre looking for is the str.encode(string-escape) function. For example, if you have a variable that you want to raw string:

a = x89
a.encode(unicode_escape)
\x89

Note: Use string-escape for python 2.x and older versions

I was searching for a similar solution and found the solution via:
casting raw strings python

Raw strings are not a different kind of string. They are a different way of describing a string in your source code. Once the string is created, it is what it is.

Convert regular Python string to raw string

Since strings in Python are immutable, you cannot make it anything different. You can however, create a new raw string from s, like this:

raw_s = r{}.format(s)

Leave a Reply

Your email address will not be published. Required fields are marked *