Ravindra Bagale · Data Scienceसर्व coursesया course चे lessonsशोधाEnglish

Data Science · मराठी आवृत्ती · Python basics

P8.1 Python Error Message (Traceback) कसा वाचायचा?

By Ravindra Bagale

हे का शिकायचं?

Error घाबरवतो, पण तो नेमकी line आणि कारण सांगतो.

हे काय आहे?

Traceback ची शेवटची line सगळ्यात महत्त्वाची: error चा प्रकार आणि कारण. वरच्या lines सांगतात error कुठे झाला.

कसं करायचं?

Step 1. शेवटची line वाचा.

Step 2. Error चा प्रकार ओळखा.

Step 3. वर line number पाहा.

1. Look at the LAST line2. Error type: what kind of problem3. Message: what exactly4. Line number: where5. Fix and run again
वरून खाली वाचा: code पासून result पर्यंतचा प्रवास

उदाहरणं: copy करा आणि चालवा

उदाहरण A: ValueError

हा code चालवा:

amount = float("12.5.0")

तुम्हाला दिसणारा output:

ValueError: could not convert string to float: '12.5.0'

याचा अर्थ: Value चुकीची होती (number नसलेला text).

उदाहरण B: KeyError

हा code चालवा:

order = {"id": 1, "amount": 450}
print(order["price"])

तुम्हाला दिसणारा output:

KeyError: 'price'

याचा अर्थ: Dictionary मध्ये ती key नव्हती. get() वापरा किंवा spelling तपासा.