Skip to content

Commit 8cc8e43

Browse files
committed
Try to fix colorama on bare windows.
1 parent 8d63be4 commit 8cc8e43

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

code/10-external-libraries/rocks-game/rpsgame.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
#################################
2+
#
3+
# NOTE TO WINDOWS USERS: Please see the following github issue
4+
# if you find weird characters instead color from colorama:
5+
#
6+
# https://github.com/talkpython/python-for-absolute-beginners-course/issues/7
7+
#
8+
# Apparently, even though it's supposed to adjust automatically, it doesn't always.
9+
# We've added a test to force it to do so at the beginning of main().
10+
#
11+
112
import datetime
213
import random
314
import json
415
import os
16+
import platform
517

18+
import colorama
619
from colorama import Fore
720
from prompt_toolkit import prompt
821
from prompt_toolkit.completion import WordCompleter, Completer, Completion
@@ -11,6 +24,10 @@
1124

1225

1326
def main():
27+
# See comment at top of file.
28+
if platform.system() == 'Windows':
29+
colorama.init(convert=True)
30+
1431
print(Fore.WHITE)
1532
log("App starting up...")
1633

code/11-error-handling/rocks-game/rpsgame.py

+6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import datetime
2+
import platform
23
import random
34
import json
45
import os
56

7+
import colorama
68
from colorama import Fore
79

810
rolls = {}
911

1012

1113
def main():
1214
try:
15+
# See comment at top of the rpsgame.py in CHAPTER 10.
16+
if platform.system() == 'Windows':
17+
colorama.init(convert=True)
18+
1319
print(Fore.WHITE)
1420
log("App starting up...")
1521

0 commit comments

Comments
 (0)