# P9.6 Python मधले नेहमीचे File Errors आणि उपाय

Source: https://ravindrabagale.com/mr/datascience/py09-how-to-read-and-write-csv-json-and-text-files-in-python/p9-6-common-file-errors-in-python-and-how-to-fix-them.html
Language: mr (Marathi with English technical terms)

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

File नसणं, चुकीचं नाव, चुकीचा encoding — हे टाळता येतात.

हे काय आहे?

FileNotFoundError म्हणजे path चुकला. UnicodeDecodeError म्हणजे encoding चुकला. Path.exists() ने आधी तपासता येतं.

कसं करायचं?

Step 1. Path.exists() ने तपासा.
Step 2. try/except FileNotFoundError वापरा.
Step 3. encoding="utf-8" द्या.

उदाहरण A: Missing file हाताळा

```python
try:
    with open("april.csv", encoding="utf-8") as f:
        print(f.read())
except FileNotFoundError:
    print("april.csv not found - export it first")
```

Output:

```text
april.csv not found - export it first
```

याचा अर्थ: File नसताना program न थांबता स्पष्ट message मिळाला.

रवींद्र बागले यांची tip

Excel च्या CSV files मध्ये सुरुवातीला लपलेलं BOM अक्षर असतं. `encoding="utf-8-sig"` ते काढतं, त्यामुळे पहिल्या column चं नाव स्वच्छ राहतं.
