O'Reilly logo

Head First Learn to Code by Eric Freeman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 11. 9 saving and retrieving files: Persistence

Image

You know you can save values in variables, but once your program ends poof!—they’re gone forever. That’s where persistent storage comes in—storage that allows your values and data to stick around a while. Most of the devices you’re going to run Python on also have persisistent storage, like hard drives and flash cards, or they may have access to storage in the cloud as well. In this chapter you’ll see how to write code to store and retrieve data from files. What good is that? Oh, anytime you want to save a user’s configuration, store the results of your big analysis for the boss, read an image into your code to process it, write some code to search a decade’s worth of email messages, reformat some data to be used in your spreadsheet app—we could go on and on, but we should probably start the chapter now.

Ready for some Crazy Libs?

No, that’s not a political statement! We’re being serious here. We’re talking about creating our own version of a game that is in the spirit of the popular Mad Libs™ games—we’ll call our version Crazy Libs.

If you didn’t play a Mad Libs–style game as a kid, here’s how it works:

Image

How to Play

  1. Ask a friend to give you a word for each blank noun, verb, and adjective, but don’t show your friend ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required