Python. Using CSV to read a file. Syntax Error
Question: The following script shows syntax error at line "with open..."

    
    
    #!/usr/bin/python
    
    import fileinput;
    import  csv;
    
    def read_csv_file ( file_name ):
    
        with open('file.csv', 'r') as my_csv_file:
            reader = csv.reader(my_csv_file)
                for row in reader:
                    print ( row )
    
    read_csv_file();
    


Answer: Your code:

    
    
    with open('file.csv', 'r') as my_csv_file:
        reader = csv.reader(my_csv_file)
            for row in reader:
                print ( row )
    

has incorrect indentation. It should be:

    
    
    with open('file.csv') as my_csv_file: # the 'r' mode is implicit
        reader = csv.reader(my_csv_file)
        for row in reader: # this line shouldn't have been indented
            print(row)
    

Additionally, the `#!/usr/bin/python` will run the script with Python 2, not
Python 3. Your system may have a very old version of Python 2 (2.4 or
previous) that doesn't recognize the
[`with`](https://www.python.org/dev/peps/pep-0343/) context manager. If you
_must_ have a shebang, make it `#!/usr/bin/env python3.5` or something
similar. Or, if you're not planning on setting the script as executable and
running it as `./scriptname.py` or whatever, just get rid of it entirely.

One more thing - don't name your file `csv.py`, as that will conflict with the
`csv` module. Avoid naming files after any modules on your system.
`csv_test.py` would be a better alternative, for example.

