Opening CSV file with pd.read_csv - any purpose for context manager?

Viewed 2427

I'm beginning to read Elegant SciPy by Nunez-Iglesias et. al, and when opening the first dataset in the book (a .txt file), the author uses

filename = 'data/counts.txt'
with open(filename, 'rt') as f:
    data_table = pd.read_csv(f, index_col=0) # Parse file with pandas

But I thought that read_csv would close the file, given that it is opening given a file descriptor (see Andy Hayden's answer here ).

So is there any purpose to the context manager here, or could we just as safely write

filename = 'data/counts.txt'
data_table = pd.read_csv(filename, index_col=0) 
1 Answers
Related