Skip to content

Commit 58c099b

Browse files
committed
validate example
1 parent 72f3e5c commit 58c099b

6 files changed

Lines changed: 16 additions & 21 deletions

File tree

example/cmd/turtle/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
1414
"""
1515

16-
# pylint: disable=locally-disabled,unused-argument,too-many-public-methods
16+
# pylint: disable=locally-disabled,unused-argument,too-many-public-methods,consider-using-with
1717

1818

1919
import cmd

example/json/parse-json.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
if os.path.isfile(filenameMy):
1818
filename = filenameMy
1919

20-
jsonfile = open(filename, "r")
21-
2220

2321
# Read from file and decode as json
24-
jsonobject = json.load(jsonfile)
22+
jsonobject = json.load(open(filename, "r"))
2523

2624

2725
# Print out the content from the dict
@@ -46,7 +44,5 @@
4644
})
4745

4846
# Open the file for writing ("w" will replace the file contents)
49-
jsonfile = open(filenameMy, "w")
50-
5147
# Encode json with pretty output (indent)
52-
json.dump(jsonobject, jsonfile, indent=4)
48+
json.dump(jsonobject, open(filenameMy, "w"), indent=4)

example/lectures/2020/kmom06/shoppinglist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def read_file(filename):
1010
return fd.read()
1111
except FileNotFoundError:
1212
print("You are missing the file")
13+
return
1314

1415

1516

example/marvin/format.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import random
77

8-
fhand = open("format.txt")
9-
line = fhand.readline()
8+
with open("format.txt") as fhand:
9+
line = fhand.readline()
1010

11-
moods = ["happy", "sad", "depressed", "angry", "annoyed", "bored", "confused", "excited", "lonely"]
12-
mood = random.choice(moods)
13-
smilies = [":)", ":(", ":D", ":/", ":|", ":'(", ":O", ":@", ":P", ":3"]
14-
smiley = random.choice(smilies)
11+
moods = ["happy", "sad", "depressed", "angry", "annoyed", "bored", "confused", "excited", "lonely"]
12+
mood = random.choice(moods)
13+
smilies = [":)", ":(", ":D", ":/", ":|", ":'(", ":O", ":@", ":P", ":3"]
14+
smiley = random.choice(smilies)
1515

16-
print(line.format(mood=mood, smiley=smiley))
16+
print(line.format(mood=mood, smiley=smiley))

example/old_exams/lp1-2018/.dbwebb/test_exam.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"""
33
Contains testcases for the individual examination.
44
"""
5+
import os
6+
import sys
57
import unittest
68
from unittest.mock import patch
9+
from unittest import TextTestRunner
710
from importlib import util
811
from io import StringIO
9-
import os
10-
import sys
11-
from unittest import TextTestRunner
1212
from examiner.exam_test_case import ExamTestCase
1313
from examiner.exam_test_result import ExamTestResult
1414

@@ -313,4 +313,3 @@ def test_d_invalid_command(self):
313313
if __name__ == '__main__':
314314
runner = TextTestRunner(resultclass=ExamTestResult, verbosity=2)
315315
unittest.main(testRunner=runner, exit=False)
316-

example/sqlite/sqlite-ping.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ def isSQLite3(filename):
3535
if getsize(filename) < 100: # SQLite database file header is 100 bytes
3636
return False
3737

38-
fd = open(filename, 'rb')
39-
Header = fd.read(100)
40-
fd.close()
38+
with open(filename, 'rb') as fd:
39+
Header = fd.read(100)
4140

4241
isFileSQLite = False
4342

0 commit comments

Comments
 (0)