SarkariResultess QA Bank

AttributeError: 'NoneType' object has no attribute ... को कैसे debug करें? इसका Python best-practice solution क्या है? — error आने पर developer क्या करे?

Other 0 Views Verified
AttributeError: 'NoneType' object has no attribute ... को कैसे debug करें? इसका Python best-practice solution क्या है? — error आने पर developer क्या करे?
Sarkari Result QA Bank
Editorially reviewed exam information

Answer & Explanation

4 Answers
Verified

None.method(obj)

None.method(obj)
Additional Explanation
यह विकल्प सही समाधान नहीं है।
Verified

obj.method() always without checking

obj.method() always without checking
Additional Explanation
यह विकल्प सही समाधान नहीं है।
Verified Correct Answer

if obj is not None: obj.method()

if obj is not None: obj.method()
Additional Explanation
None पर attribute/method access करने से पहले value check करें। पहले traceback की exact line और input value check करें।
Verified

obj = None.method()

obj = None.method()
Additional Explanation
यह विकल्प सही समाधान नहीं है।