1

When I 'print' some hex string, some interesting error information in python, I wonder why this error is caused.

Win10(I tried it on ubuntu, No ERROR),python 2.7

enc_hex = '''f982f01c'''
enc_ascii = enc_hex.decode('hex')
print(enc_ascii)
Traceback (most recent call last):
  File ".\xxxx.py", line 7, in <module>
    print(enc_ascii)
IOError: [Errno 2] No such file or directory

Well,in fact I want to know why "print" a special set of hex will cause file operation, other hex string will not error

  • there is no parenthesis for print in python 2.7 `print enc_ascii` https://docs.python.org/2/tutorial/inputoutput.html – WSMathias9 Apr 16 '19 at 03:48
  • 1
    @WSMathias9 You still can use it with parens – U13-Forward Apr 16 '19 at 03:48
  • Possible duplicate of [Convert from ASCII string encoded in Hex to plain ASCII?](https://stackoverflow.com/questions/9641440/convert-from-ascii-string-encoded-in-hex-to-plain-ascii) – WSMathias9 Apr 16 '19 at 05:44

2 Answers2

0

Try using codecs.decode:

import codecs
enc_hex = '''f982f01c'''
enc_ascii = codecs.decode(enc_hex, 'hex')
print(enc_ascii)

Output:

b'\xf9\x82\xf0\x1c'
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
0

it seems like directory problems . in windows you have to use forward slash (/) while accessing the directory.similar was happened in my case then i use forward slash in windows then it works.

Anil Sah
  • 1,502
  • 1
  • 9
  • 11