Skip to content

STY: 'open()' and 'close()' to 'with' context manager #29851

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 3 commits into from
Nov 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pandas/io/clipboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,12 @@ def copy_dev_clipboard(text):
if "\r" in text:
warnings.warn("Pyperclip cannot handle \\r characters on Cygwin.")

fo = open("/dev/clipboard", "wt")
fo.write(text)
fo.close()
with open("/dev/clipboard", "wt") as fo:
fo.write(text)

def paste_dev_clipboard():
fo = open("/dev/clipboard", "rt")
content = fo.read()
fo.close()
with open("/dev/clipboard", "rt") as fo:
content = fo.read()
return content

return copy_dev_clipboard, paste_dev_clipboard
Expand Down