“Błąd Pythona” Kod odpowiedzi

Jak wydrukować błąd w próbach oprócz Pythona

try:
  # some code
except Exception as e:
	print("ERROR : "+str(e))
Jenova

Wydrukuj typ wyjątku Python

try:
    someFunction()
except Exception as ex:
    template = "An exception of type {0} occurred. Arguments:\n{1!r}"
    message = template.format(type(ex).__name__, ex.args)
    print (message)
Graceful Gannet

Z wyjątkiem wyjątku:

>>> def catch():
...     try:
...         asd()
...     except Exception as e:
...         print e.message, e.args
... 
>>> catch()
global name 'asd' is not defined ("global name 'asd' is not defined",)
Distinct Dormouse

Złap błąd Python

import traceback

dict = {'a':3,'b':5,'c':8}
try:
  print(dict[q])
 
except:
  traceback.print_exc()
  
# This will trace you back to the line where everything went wrong. 
# So in this case you will get back line 5    
  
  
Poised Peccary

plik Python Otwórz próbę oprócz błędu

def FileCheck(fn):
    try:
      open(fn, "r")
      return 1
    except IOError:
      print "Error: File does not appear to exist."
      return 0

result = FileCheck("testfile")
print result
Poor Panther

Błąd Pythona

UsageError: Cell magic `%%mysql` not found.
Gaurav Amrutkar

Odpowiedzi podobne do “Błąd Pythona”

Pytania podobne do “Błąd Pythona”

Więcej pokrewnych odpowiedzi na “Błąd Pythona” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu