Print raw string from variable? (not getting the answers)

后端 未结 11 910
后悔当初
后悔当初 2020-12-04 10:14

I\'m trying to find a way to print a string in raw form from a variable. For instance, if I add an environment variable to Windows for a path, which might look like \'

11条回答
  •  有刺的猬
    2020-12-04 11:07

    In general, to make a raw string out of a string variable, I use this:

    string = "C:\\Windows\Users\alexb"
    
    raw_string = r"{}".format(string)
    

    output:

    'C:\\\\Windows\\Users\\alexb'
    

提交回复
热议问题