Python SyntaxError: EOF while scanning a 3 quoted string literal
My script:
# -*- coding: utf-8 -*-
RAW_ZIP = """PK šîF4"àµÑ$= tcp_host.exeì]
|GßË]È%\Èa/íµMኦ%ElÀBê…|bÜåÈ"#ƒMIzÙ£¡†<¢\·±¨UQ«©ZµjU´ÑÖh©´"ZªhQ—ÛôB¡œÿ7³{ùÀ¶~ýüéÁìì̼yó%ô6"›¸ŸIÖÃ%,…N–*§xŒ4xF*ÓΞŒÎd.•8¹l¹ j'4ŸZëí‚R;»‰MÊiÈL`
...long string...
"Ýä+\è\n$NKƒ—u-Èp‰f(OY3ò ˆh&‚"¾ ôE\>Ó]lÀY˜ *¸|ÐZV=Èø4«›„׋³\1òNDØø†R¼pžH5ÇHeòÓêxtŠ‹‰Yí2tªÖE˜"&-')r¢Wå¯AÏk"Õhv%r³\ã&·ù$šR¹ª6ñÕ«›ûP¨6³ÍÍý§ŽÚˆœÛ¢|Øâbý63>8£zŠn`–DÞøUâV"cO§E©¸z½õ—OùÛª|ä‹P‘[¾†ä9ÝGrŠüšK(EöŒíj»<£>M|ù^–¿¦Pß8¯Òw‘é’*3ŸÖh†¬®˜‹µ[]T°³CxÝ»âUŸ³Ê"RzY,ûŽ—o È#H¶®’ˆ"
>ÑaËm1èØ÷‰ )ô§ìKvÐ
c"""
But when I run it I get the error:
SyntaxError: EOF while scanning triple-quoted string literal
Why?
+3
source to share
1 answer
Reason: Python thinks the file ends on your line.
Guessing: For some reason character 26 is EOF in some cases.
Motivation:
Python files are text files whereas zip files are binary. You don't have to mix them because
- text files are encoded whereas binaries do not.
- after all Windows, Mac and Linux are different. Text files can be modified accordingly.
In both cases, the zip file will be split.
Solution:
Encoding.
>>> import base64
>>> base64.b64encode(b"""raw string""") # here you get the encoded result
b'cmF3IHN0cmluZw=='
>>> base64.b64decode(b'cmF3IHN0cmluZw==') # this is part of your Python file.
b'raw string'
+3
source to share