Fix Python – What is a good way to handle exceptions when trying to read a file in python?

I want to read a .csv file in python.

I don’t know if the file exists.
My current solution is below. It feels sloppy to me because the two separate exception tests are awkwardly juxtaposed.

Is there a prettier way to do it?
import csv
fName = “aFile.csv”

try:
with open(fName, ‘r’) as f:
reader = csv.reader(f)
for row in ….

Fix Python – Cost of exception handlers in Python

In another question, the accepted answer suggested replacing a (very cheap) if statement in Python code with a try/except block to improve performance.
Coding style issues aside, and assuming that the exception is never triggered, how much difference does it make (performance-wise) to have an exception handler, versus not having one, versus having….

Fix Python – How to get exception message in Python properly

What is the best way to get exceptions’ messages from components of standard library in Python?
I noticed that in some cases you can get it via message field like this:
try:
pass
except Exception as ex:
print(ex.message)

but in some cases (for example, in case of socket errors) you have to do something like this:
try:
pass
except socket.err….

Fix Python – “Inner exception” (with traceback) in Python?

My background is in C# and I’ve just recently started programming in Python. When an exception is thrown I typically want to wrap it in another exception that adds more information, while still showing the full stack trace. It’s quite easy in C#, but how do I do it in Python?
Eg. in C# I would do something like this:
try
{
ProcessFile(filePath);….

Fix Python – How to handle exceptions in a list comprehensions?

I have some a list comprehension in Python in which each iteration can throw an exception.
For instance, if I have:
eggs = (1,3,0,3,2)

[1/egg for egg in eggs]

I’ll get a ZeroDivisionError exception in the 3rd element.
How can I handle this exception and continue execution of the list comprehension?
The only way I can think of is to use a helpe….