Skip to content

Commit 5502ea1

Browse files
committed
Clean up code format for emerging standard with ruff format.
1 parent 309e178 commit 5502ea1

34 files changed

+174
-154
lines changed

apps/py/ch03_lang/L01_structure.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
def main():
2-
name = input("What is your name? ")
2+
name = input('What is your name? ')
33
some_method(name)
44

55

66
def some_method(name):
77
if name.strip().lower() == 'michael':
8-
print("Hello old friend!")
8+
print('Hello old friend!')
99
else:
10-
print(f"Nice to meet you {name}.")
11-
print("My name is Python!")
10+
print(f'Nice to meet you {name}.')
11+
print('My name is Python!')
1212

1313

1414
if __name__ == '__main__':

apps/py/ch03_lang/L02_iteration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
def main():
2-
print("Python iteration demo")
2+
print('Python iteration demo')
33

44
# while True:
55
# name = input("What is your name? ")
@@ -10,16 +10,16 @@ def main():
1010

1111
nums = [1, 5, 8, 10, 7, 2] # <-- List<object>
1212
for n in nums:
13-
print(f"The next number is {n}.")
13+
print(f'The next number is {n}.')
1414
print()
1515

1616
for idx, n in enumerate(nums, start=1):
17-
print(f"The {idx}th number is {n}.")
17+
print(f'The {idx}th number is {n}.')
1818

1919
# NO for (i=0; i < len(nums); i++)
2020
print()
2121
for _ in range(1, 6):
22-
print("This time!")
22+
print('This time!')
2323

2424

2525
if __name__ == '__main__':

apps/py/ch03_lang/L03_function_basics.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def main():
1818
if evaluate_guess(guess, the_number):
1919
break
2020

21-
print(f"You got the number in {count} attempts. Thanks for playing, bye!")
21+
print(f'You got the number in {count} attempts. Thanks for playing, bye!')
2222

2323

2424
def evaluate_guess(guess, number):
@@ -35,14 +35,14 @@ def evaluate_guess(guess, number):
3535
def get_guess():
3636
val = None
3737
try:
38-
text = input("What number am I thinking of? ")
38+
text = input('What number am I thinking of? ')
3939
val = int(text)
4040
if val < 1 or 100 < val:
41-
print(f"{val} is not between 1 and 100.")
41+
print(f'{val} is not between 1 and 100.')
4242
return None
4343
return val
4444
except:
45-
print(f"{val} is not an integer!")
45+
print(f'{val} is not an integer!')
4646
return None
4747

4848

@@ -54,7 +54,7 @@ def show_header():
5454
print('-------------------------------------------')
5555
print()
5656
print("I'm thinking of a number between 1 & 100. ")
57-
print("How many steps can you guess it in?")
57+
print('How many steps can you guess it in?')
5858
print()
5959

6060
# implicit

apps/py/ch03_lang/L04_function_args.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
def main():
2-
print("say_hello()")
2+
print('say_hello()')
33
say_hello()
44
print()
55

6-
print("say_hello(name)")
7-
say_hello("Zoe")
6+
print('say_hello(name)')
7+
say_hello('Zoe')
88
print()
99

10-
print("say_hello(name, times)")
11-
say_hello("Zoe", 5)
10+
print('say_hello(name, times)')
11+
say_hello('Zoe', 5)
1212
print()
1313

14-
print("say_hello(name, times, 1, 2, 3, 4)")
15-
say_hello("Zoe", 5, 1, 2, 3, 4)
14+
print('say_hello(name, times, 1, 2, 3, 4)')
15+
say_hello('Zoe', 5, 1, 2, 3, 4)
1616
print()
1717

18-
print("say_hello(name, times, 1, 2, 3, 4, val=7, mode=prod)")
19-
say_hello("Zoe", 5, 1, 2, 3, 4, val=7, mode="prod")
18+
print('say_hello(name, times, 1, 2, 3, 4, val=7, mode=prod)')
19+
say_hello('Zoe', 5, 1, 2, 3, 4, val=7, mode='prod')
2020
print()
2121

2222
# THis isn't really an option
@@ -30,7 +30,7 @@ def main():
3030

3131

3232
def say_hello(name='friend', times=1, *args, **kwargs):
33-
print(f"Hello {name} with times={times}, args={args}, kwargs={kwargs}!")
33+
print(f'Hello {name} with times={times}, args={args}, kwargs={kwargs}!')
3434

3535

3636
if __name__ == '__main__':

apps/py/ch03_lang/L06_ternary.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
def main():
22
while True:
3-
text = input("Enter a number: ")
3+
text = input('Enter a number: ')
44
if not text:
5-
print("Later...")
5+
print('Later...')
66
break
77

88
num = int(text)
9-
num_class = "small" if num < 100 else "huge!"
10-
print(f"The number is {num_class}")
9+
num_class = 'small' if num < 100 else 'huge!'
10+
print(f'The number is {num_class}')
1111

1212

1313
if __name__ == '__main__':

apps/py/ch03_lang/L08_closures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ def main():
1111

1212

1313
def create_counter(start_val, counter_id):
14-
print(f"Creating a counter with start value {start_val}...")
14+
print(f'Creating a counter with start value {start_val}...')
1515

1616
inc = start_val
1717

1818
def counter():
1919
nonlocal inc
2020
inc += 1
21-
print(f"#{counter_id}: Counting {start_val}\t -->\t{inc}.")
21+
print(f'#{counter_id}: Counting {start_val}\t -->\t{inc}.')
2222

2323
return counter
2424

apps/py/ch03_lang/L09_types.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33

44
class Wizard:
5-
65
def __init__(self):
76
self.name: Optional[str] = None
87
self.level: int = 0
98

109
@staticmethod
11-
def train(base_level: int) -> "Wizard":
10+
def train(base_level: int) -> 'Wizard':
1211
w = Wizard()
1312
w.level = base_level
1413

@@ -18,7 +17,7 @@ def train(base_level: int) -> "Wizard":
1817
def main():
1918
gandolf: Wizard = Wizard.train(100)
2019
gandolf.level += 1
21-
print(f"The wizard Gandolf is level {gandolf.level}")
20+
print(f'The wizard Gandolf is level {gandolf.level}')
2221

2322

2423
if __name__ == '__main__':

apps/py/ch03_lang/L10_errors.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ def main():
66

77
for v in values:
88
try:
9-
print(Fore.YELLOW + f"Calling sketchy_method with {v}...", flush=True)
9+
print(Fore.YELLOW + f'Calling sketchy_method with {v}...', flush=True)
1010
sketchy_method(v)
1111
except BrokenPipeError:
12-
print(Fore.LIGHTRED_EX + " **** Network error, check our wifi.")
12+
print(Fore.LIGHTRED_EX + ' **** Network error, check our wifi.')
1313
except ArithmeticError:
14-
print(Fore.LIGHTRED_EX + f" **** Cannot compute with {v}!")
14+
print(Fore.LIGHTRED_EX + f' **** Cannot compute with {v}!')
1515
except Exception as e:
16-
print(Fore.LIGHTRED_EX + f" **** Error: {type(e).__name__} ==> {str(e)}")
16+
print(Fore.LIGHTRED_EX + f' **** Error: {type(e).__name__} ==> {str(e)}')
1717
# finally:
1818
# print("Finally!")
1919

@@ -22,13 +22,13 @@ def sketchy_method(value: int):
2222
import random
2323

2424
if not value:
25-
raise ValueError(f"{value} is not valid.")
25+
raise ValueError(f'{value} is not valid.')
2626
elif value % 6 == 0:
2727
raise ArithmeticError()
2828
elif random.randint(1, 10) == 3:
29-
raise BrokenPipeError("Bad network!")
29+
raise BrokenPipeError('Bad network!')
3030

31-
print("sketchy_method() actually worked!")
31+
print('sketchy_method() actually worked!')
3232

3333

3434
if __name__ == '__main__':

apps/py/ch03_lang/L11_using.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
def main():
55
data = {
6-
"name": "Michael",
7-
"language": "Python",
6+
'name': 'Michael',
7+
'language': 'Python',
88
}
99

1010
with open('file.json', 'w', encoding='utf-8') as fout:
1111
json.dump(data, fout, indent=True)
1212

13-
print("Saved to local file: file.json")
13+
print('Saved to local file: file.json')
1414

1515

1616
if __name__ == '__main__':

apps/py/ch03_lang/L12_switch.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33

44
def main():
55
while True:
6-
7-
text = input("Enter a number between 1 & 4: ")
6+
text = input('Enter a number between 1 & 4: ')
87
if not text:
9-
print("Later!")
8+
print('Later!')
109
break
1110

1211
num = int(text)
1312

1413
with switch(num) as s:
15-
s.case(1, lambda: print("One is fun!"))
16-
s.case(2, lambda: print("2 * 2 = 4"))
17-
s.case(3, lambda: print("Three and free."))
18-
s.case(4, lambda: print("4 more!"))
14+
s.case(1, lambda: print('One is fun!'))
15+
s.case(2, lambda: print('2 * 2 = 4'))
16+
s.case(3, lambda: print('Three and free.'))
17+
s.case(4, lambda: print('4 more!'))
1918
s.case(closed_range(10, 20), lambda: num * num)
20-
s.default(lambda: print(f"Say what? {num}."))
19+
s.default(lambda: print(f'Say what? {num}.'))
2120

22-
print(f"Done and got {s.result}")
21+
print(f'Done and got {s.result}')
2322

2423

2524
if __name__ == '__main__':

0 commit comments

Comments
 (0)