Hardware Reference
In-Depth Information
FIGURE.6-1 Random tips pop up on the chat as you play Minecraft.
CHALLENGE
Add more Minecraft tips to your tips.txt file based on your experience playing
Minecraft. Give your tips.txt and your tipChat.py program to a friend who is
learning Minecraft and let them use it to quickly learn how to do amazing things in
the game. You could even write a whole series of tips.txt files with different top-
ics and different amounts of detail depending on the ability of the player, and publish
them on a small website for others to use along with your tipChat.py program.
DIGGING INTO THE CODE
In the tipChat.py program, a little bit of magic happens in the following line:
f = open(FILENAME, "r")
The open() function opens the file named in the FILENAME constant—but
what does that "r" at the end mean? When you open a file, you have to tell the
open() function what level of access you want to that file. In this case, the
"r" means that you only want to read the file. If you accidentally try to write to
the file, you will get an error message. This protects your files by preventing
accidental damage. If you want to open a file and write to it, you can use a "w"
instead (or if you want to read and write a file at the same time, use "rw" ).
continued
Search WWH ::




Custom Search