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

后端 未结 11 996
后悔当初
后悔当初 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条回答
  •  旧时难觅i
    2020-12-04 11:04

    I have my variable assigned to big complex pattern string for using with re module and it is concatenated with few other strings and in the end I want to print it then copy and check on regex101.com. But when I print it in the interactive mode I get double slash - '\\w' as @Jimmynoarms said:

    The Solution for python 3x:

    print(r'%s' % your_variable_pattern_str)
    

提交回复
热议问题