Skip to content

REF: Use more context managers to close files #45579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 24, 2022

Conversation

mroeschke
Copy link
Member

  • tests added / passed
  • Ensure all linting tests pass, see here for how to run them

f = open("foo.csv", "w")
f.write("date,A,B,C\n20090101,a,1,2\n20090102,b,3,4\n20090103,c,4,5")
f.close()
with open("foo.csv", "w") as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using mode="w" might be slightly clearer

@mroeschke mroeschke added the Refactor Internal refactoring of code label Jan 24, 2022
@mroeschke mroeschke added this to the 1.5 milestone Jan 24, 2022
@mroeschke
Copy link
Member Author

Failure unrelated.

@mroeschke mroeschke merged commit 991fc27 into pandas-dev:main Jan 24, 2022
@mroeschke mroeschke deleted the ref/context_manager branch January 24, 2022 04:03
yehoshuadimarsky pushed a commit to yehoshuadimarsky/pandas that referenced this pull request Jul 13, 2022
* Use more context managers

* Add more context managers

* Context closing for openpyxl workbooks

* Context close xlrd objects

* Fix method name

* more closing

* Use mode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor Internal refactoring of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants