Skip to Content
Programming the Raspberry Pi, Third Edition: Getting Started with Python, 3rd Edition
book

Programming the Raspberry Pi, Third Edition: Getting Started with Python, 3rd Edition

by Simon Monk
June 2021
Beginner
208 pages
3h 50m
English
McGraw-Hill Education TAB
Content preview from Programming the Raspberry Pi, Third Edition: Getting Started with Python, 3rd Edition

6

Files and the Internet

Python makes it easy for your programs to use files and connect to the Internet. You can read data from files, write data to files, and fetch content from the Internet. You can even check for new mail and tweet—all from your program.

Files

When you run a Python program, any values you have in variables will be lost. Files provide a means of making data more permanent.

Reading Files

Python makes reading the contents of a file extremely easy. As an example, we can convert the Hangman program from Chapter 4 to read the list of words from a file rather than have them fixed in the program.

First of all, start a new file in Mu and put some words in it, one per line. Then save the file with the name hangman_words.txt in the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

Raspberry Pi 3 Cookbook for Python Programmers - Third Edition

Steven Lawrence Fernandes, Tim Cox
Getting Started With Arduino, 4th Edition

Getting Started With Arduino, 4th Edition

Massimo Banzi, Michael Shiloh

Publisher Resources

ISBN: 9781264257362