Last active
April 11, 2021 05:47
-
-
Save BeMg/5d7ce0fd1e2774466a87c57f96a34b9c to your computer and use it in GitHub Desktop.
show file raw byte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == "__main__": | |
rst = "" | |
filename = "SImulatedDataAnalysis.py" | |
with open(filename, "rb") as f: | |
byte = f.read(1) | |
cnt = 0 | |
while byte: | |
cnt = cnt + 1 | |
byte = f.read(1) | |
print("origin {} -> utf-8 ? {}".format(byte.hex(), byte)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pkgutil | |
import os | |
import encodings | |
def all_encodings(): | |
modnames = set( | |
[modname for importer, modname, ispkg in pkgutil.walk_packages( | |
path=[os.path.dirname(encodings.__file__)], prefix='')]) | |
aliases = set(encodings.aliases.aliases.values()) | |
return modnames.union(aliases) | |
if __name__ == "__main__": | |
rst = "" | |
filename = "ParametersScanCal.py" | |
for enc in all_encodings(): | |
print("\n\n\n=======try {}==========\n\n".format(enc)) | |
with open(filename, "rb") as f: | |
byte = f.read(2) | |
cnt = 0 | |
while byte: | |
byte = f.read(2) | |
# print("origin {} -> utf-8 ? {}".format(byte.hex(), byte)) | |
if str(byte).find("?") != -1: | |
# print("{} -> {}".format(str(byte), str(byte).find("?"))) | |
rst += "@@" | |
elif str(byte).find("\\x") != -1: | |
try: | |
rst += str(byte.decode(enc)) | |
except: | |
rst += str(byte) | |
else: | |
rst += str(byte.decode("utf-8")) | |
print(rst) | |
print("\n\n\n=======finish {}==========\n\n".format(enc)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment