Python Crash Course: A Hands-On, Project-Based Introduction to Programming
Rate it:
37%
Flag icon
contents = file_object.read()
37%
Flag icon
pi_digits.txt, we use the read()
37%
Flag icon
pi_digits.txt to the open() function,
37%
Flag icon
with open('text_files/filename.txt') as file_object:
37%
Flag icon
with open(file_path) as file_object:
38%
Flag icon
file_object:
38%
Flag icon
for line in file_object:
38%
Flag icon
➊ with open(filename, 'w') as file_object: ➋     file_object.write("I love programming.")
39%
Flag icon
file_object.write("I love creating new games.")
39%
Flag icon
try-except
39%
Flag icon
try-except
39%
Flag icon
the try-except block,
39%
Flag icon
Handling errors correctly is especially important when the program has more work to do after the error occurs.
40%
Flag icon
words = contents.split()
41%
Flag icon
You might allow users to store preferences
41%
Flag icon
dictionaries. When users close a program, you’ll almost always want to save the information they entered.
41%
Flag icon
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.
41%
Flag icon
It’s a useful and portable format, and it’s easy to learn.
41%
Flag icon
The JSON (JavaScript Object Notation) format was originally developed for JavaScript.
41%
Flag icon
import json
41%
Flag icon
numbers = [2, 3, 5, 7, 11, 13] ➊ filename = 'numbers.json' ➋ with open(filename, 'w') as f_obj: ➌     json.dump(numbers, f_obj)
41%
Flag icon
json.dump(),
41%
Flag icon
json.load(f_obj)
42%
Flag icon
Python’s unittest module.
42%
Flag icon
code. A unit test verifies that one specific aspect of a function’s behavior is correct.
42%
Flag icon
with full coverage
42%
Flag icon
import unittest
42%
Flag icon
class NamesTestCase(unittest.TestCase):
42%
Flag icon
➌         self.assertEqual(formatted_name, 'Janis Joplin')
42%
Flag icon
unittest.main()
43%
Flag icon
Testing a Class
44%
Flag icon
def setUp(self):            """            Create a survey and a set of responses for use in all test methods.
45%
Flag icon
the unittest module.
45%
Flag icon
the setUp() method to efficiently create instances and attributes from your classes that can be used in all the
45%
Flag icon
Other programmers respect your projects more if you include some initial tests. They’ll
45%
Flag icon
Write tests for the most critical behaviors of your functions and classes,
45%
Flag icon
Alien Invasion:
45%
Flag icon
Data Visualization
45%
Flag icon
field of data mining, which is a highly sought-after skill in the world today.
45%
Flag icon
Web Applications
45%
Flag icon
Django package
45%
Flag icon
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.
45%
Flag icon
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.
71%
Flag icon
Installing Requests The requests package allows a Python program to easily request information from a website and examine the response that’s returned.
71%
Flag icon
pip install --user requests
74%
Flag icon
Django is a web framework—a set of tools designed to help you build interactive websites.
74%
Flag icon
A virtual environment is a place on your system where you can install packages and isolate them from all other Python packages.
74%
Flag icon
Create a new directory for your project called learning_log, switch to that directory in a terminal, and create a virtual environment.
74%
Flag icon
learning_log$ python -m venv ll_env
74%
Flag icon
running the venv module and using it to create a virtual environment named ll_env.