如何在Windows中使用多行字符串打印新行换行?

时间:2015-12-09 21:56:33

标签: python

我已阅读如何在python中取消反斜杠转义字符串? (How do I un-escape a backslash-escaped string in python?)并且答案不起作用,也许是因为我正在运行Windows。

In [1]: sql = '''
SELECT {column_specs}
    FROM {tables}
    WHERE year = {year} AND game_ref = games.id AND
        {id_matches} AND
        EVENT_CD IN ({event_codes})'''
In [2]: sql.decode('string_escape')
Out[2]: '\nSELECT {column_specs}\n    FROM {tables}\n    WHERE year = {year} AND game_ref = games.id AND\n        {id_matches} AND\n        EVENT_CD IN ({event_codes})'

1 个答案:

答案 0 :(得分:2)

尝试

print sql.decode('string_escape')

输出

SELECT {column_specs}
    FROM {tables}
    WHERE year = {year} AND game_ref = games.id AND
        {id_matches} AND
        EVENT_CD IN ({event_codes})