簡體   English   中英

使用“ PRINT”時,“無此文件或目錄”錯誤信息

[英]'No such file or directory' ERROR information when using “PRINT”

當我“打印”一些十六進制字符串,一些有趣的python錯誤信息時,我想知道為什么會導致此錯誤。

Win10(我在ubuntu上嘗試過,沒有錯誤),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

好吧,實際上我想知道為什么“打印”一組特殊的十六進制會導致文件操作,而其他十六進制字符串不會出錯

嘗試使用codecs.decode

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

輸出:

b'\xf9\x82\xf0\x1c'

似乎是目錄問題。 在Windows中,訪問目錄時必須使用正斜杠(/)。在我的情況下發生了類似的情況,然后我在Windows中使用了正斜杠,然后就可以了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM