More on this book
Community
Kindle Notes & Highlights
by
Eric Matthes
Started reading
November 1, 2018
contents = file_object.read()
pi_digits.txt, we use the read()
pi_digits.txt to the open() function,
with open('text_files/filename.txt') as file_object:
with open(file_path) as file_object:
file_object:
for line in file_object:
➊ with open(filename, 'w') as file_object: ➋ file_object.write("I love programming.")
file_object.write("I love creating new games.")
try-except
try-except
the try-except block,
Handling errors correctly is especially important when the program has more work to do after the error occurs.
words = contents.split()
You might allow users to store preferences
dictionaries. When users close a program, you’ll almost always want to save the information they entered.
The json module allows you to dump simple Python data structures into a file and load the data from that file the next time the program runs.
It’s a useful and portable format, and it’s easy to learn.
The JSON (JavaScript Object Notation) format was originally developed for JavaScript.
import json
numbers = [2, 3, 5, 7, 11, 13] ➊ filename = 'numbers.json' ➋ with open(filename, 'w') as f_obj: ➌ json.dump(numbers, f_obj)
json.dump(),
json.load(f_obj)
Python’s unittest module.
code. A unit test verifies that one specific aspect of a function’s behavior is correct.
with full coverage
import unittest
class NamesTestCase(unittest.TestCase):
➌ self.assertEqual(formatted_name, 'Janis Joplin')
unittest.main()
Testing a Class
def setUp(self): """ Create a survey and a set of responses for use in all test methods.
the unittest module.
the setUp() method to efficiently create instances and attributes from your classes that can be used in all the
Other programmers respect your projects more if you include some initial tests. They’ll
Write tests for the most critical behaviors of your functions and classes,
Alien Invasion:
Data Visualization
field of data mining, which is a highly sought-after skill in the world today.
Web Applications
Django package
pip is a program that handles the downloading and installing of Python packages for you. The following sections will show you how to install packages with pip.
Installing Python Packages with pip The most recent versions of Python come with pip installed, so first check whether pip is already on your system. With Python 3, pip is sometimes called pip3.
Installing Requests The requests package allows a Python program to easily request information from a website and examine the response that’s returned.
pip install --user requests
Django is a web framework—a set of tools designed to help you build interactive websites.
A virtual environment is a place on your system where you can install packages and isolate them from all other Python packages.
Create a new directory for your project called learning_log, switch to that directory in a terminal, and create a virtual environment.
learning_log$ python -m venv ll_env
running the venv module and using it to create a virtual environment named ll_env.

