python3.5打開長線碼成多線(語法錯誤:意外的字符續行字符後)
正則表達式
Monat_pattern = r"(?P<Monat>[A-Z][a-z][a-z])"
Tag_pattern = r"(?P<Tag>\d\d)"
Uhrzeit_pattern = r"(?P<Uhrzeit>\d\d:\d\d:\d\d)"
Servername_pattern = r"(?P<Servername>[\w|\.]*)"
ServerID_pattern = r"(?P<ServerID>\w*\[\d*\]:\s\w*)"
concate他們:
pattern = Monat_pattern + r"\s*" +\\
Tag_pattern + r"\s*" +\\
Uhrzeit_pattern + r"\s*" +\\
Servername_pattern + r"\s*"+\\
ServerID_pattern + r"\s*
瞭解到,如果有「 \「在字符串中,我需要使用」\\「來拼接
我得到錯誤:
File "<ipython-input-115-1ca2b20ef199>", line 1
pattern = Monat_pattern + r"\s*" +\ Tag_pattern + r"\s*" +\ Uhrzeit_pattern + r"\s*" +\ Servername_pattern + r"\s*"+\\
^
SyntaxError: unexpected character after line continuation character
你爲什麼使用* double *反斜槓?你只需要一個。 –
您不需要在字符串文字之外轉義反斜槓。 – vaultah
你可能想嘗試https://pypi.python.org/pypi/autopep8自動格式化代碼 – titus