Skip to content

Instantly share code, notes, and snippets.

@BeMg
Last active April 11, 2021 05:47
Show Gist options
  • Save BeMg/5d7ce0fd1e2774466a87c57f96a34b9c to your computer and use it in GitHub Desktop.
Save BeMg/5d7ce0fd1e2774466a87c57f96a34b9c to your computer and use it in GitHub Desktop.
show file raw byte
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))
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