import sys,os def main(): args = sys.argv if len(args) < 2: return "Usage: python xx.py filePath encode/decode" if not os.path.exists(args[1]): return "Usage: python xx.py filePath encode/decode" if args[2] == 'encode': fileName = args[1] fileName_new = fileName + ".hexEncode" with open(fileName,"rb") as f: with open(fileName_new,'w',encoding="utf-8") as f2: f2.write(bytes.hex(f.read())) elif args[2] == 'decode': fileName = args[1] fileName_new = fileName + ".hexDecode" with open(fileName,"r",encoding="utf-8") as f: with open(fileName_new,'wb') as f2: f2.write(bytes.fromhex(f.read())) else: return "Usage: python xx.py filePath encode/decode" return "success" if __name__ == "__main__": print(main())