SarkariResultess QA Bank

Python में text file read करने का सही तरीका क्या है? — error आने पर developer क्या करे?

Other 0 Views Verified
Python में text file read करने का सही तरीका क्या है? — error आने पर developer क्या करे?
Sarkari Result QA Bank
Editorially reviewed exam information

Answer & Explanation

4 Answers
Verified Correct Answer

with open('data.txt', 'r', encoding='utf-8') as f: text = f.read()

with open('data.txt', 'r', encoding='utf-8') as f: text = f.read()
Additional Explanation
with open context manager file को safely close करता है। पहले traceback की exact line और input value check करें।
Verified

file.read('data.txt')

file.read('data.txt')
Additional Explanation
यह विकल्प सही समाधान नहीं है।
Verified

open_file('data.txt')

open_file('data.txt')
Additional Explanation
यह विकल्प सही समाधान नहीं है।
Verified

with file('data.txt'):

with file('data.txt'):
Additional Explanation
यह विकल्प सही समाधान नहीं है।