Všechno Nové

user:thomas gists created by user

title:mygist gists with given title

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

Přihlásit se


Všechno Nové Přihlásit se

All gists matching topic file-io

Nedávno Vytvořeno
Nejméně nedávno Vytvořeno
Nedávno Aktualizováno
Nejméně nedávno Aktualizováno

timmy / 使用 errno 處理標準錯誤代碼

0 Lajky
0 Forky
3 Soubory
Naposledy aktivní 9 months ago
errno 提供標準錯誤代碼,適用於 檔案操作、系統調用、例外處理,可提高錯誤訊息的可讀性,並方便比對特定錯誤類型。
errno error-handling file-io python system-calls
1 import errno
2 import os
3
4 try:
5 os.remove("non_existent_file.txt") # 嘗試刪除不存在的檔案
6 except OSError as e:
7 if e.errno == errno.ENOENT:
8 print("錯誤:檔案不存在")
9 elif e.errno == errno.EACCES:
10 print("錯誤:權限不足")
Novější Starší

Vytvořeno pomocí Opengist ⋅ Load: 22ms⋅

Čeština
Čeština Deutsch English Español Français Magyar Italiano 日本語 Polski Português Русский Türkçe Українська 中文 繁體中文