Skip to content

Commit 7056221

Browse files
committed
Use context manager for this file open
Yes, competitors aren't neccesarily going to know exactly what this means and, no, I'm not going to explain it inline. However it *will* match other examples they see around the place and is preferable as a source of copy/paste than not having a context manager here.
1 parent 57261d5 commit 7056221

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

programming/sr/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,8 @@ usbkey
8181
R = Robot()
8282
print "The path to the USB key is:", R.usbkey
8383
print "My file on the USB contains:"
84-
f = open(os.path.join(R.usbkey, "my-file.txt"), "r")
85-
print f.read()
86-
f.close()
84+
with open(os.path.join(R.usbkey, 'my-file.txt'), 'r') as f:
85+
print f.read()
8786
~~~~~
8887

8988
[Custom Robot Object Initialisation](#CustomRobotInit) {#CustomRobotInit}

0 commit comments

Comments
 (0)