AutomateTheBoringStuff.Ch15 package

Submodules

AutomateTheBoringStuff.Ch15.P1_timeModule module

Time module

This program uses time to reference the Unix epoch as a timestamp.

AutomateTheBoringStuff.Ch15.P1_timeModule.main()[source]

AutomateTheBoringStuff.Ch15.P2_calcProd module

Calculate product

Uses time to profile a function that calculates the product of the first 100,000 numbers.

Note

  • Added cProfile for an execution profile. Does add overhead, so not suitable for benchmarking.
  • Added timeit for accurate execution timing.
AutomateTheBoringStuff.Ch15.P2_calcProd.calcProd() → int[source]

Calculate product

Calculates the product of the first 100000 integers using a for loop.

Returns:Integer product.
AutomateTheBoringStuff.Ch15.P2_calcProd.main()[source]

AutomateTheBoringStuff.Ch15.P3_stopwatch module

Stopwatch

A simple stopwatch program with lap times.

AutomateTheBoringStuff.Ch15.P3_stopwatch.main()[source]

AutomateTheBoringStuff.Ch15.P4_datetimeModule module

datetime module

This program uses datetime to manipulate dates and times.

AutomateTheBoringStuff.Ch15.P4_datetimeModule.main()[source]

AutomateTheBoringStuff.Ch15.P5_threadDemo module

Thread demo

This program uses threading to demonstrate multithreading.

AutomateTheBoringStuff.Ch15.P5_threadDemo.main()[source]
AutomateTheBoringStuff.Ch15.P5_threadDemo.takeANap() → None[source]

Take a nap

Simple 5 second timer using time.sleep() followed by a ‘Wake up!’ print statement.

Returns:None. Waits 5 seconds, then prints an exclamation.

AutomateTheBoringStuff.Ch15.P6_multithreading module

Multithreading

This program demonstrates threading.Thread on print().

AutomateTheBoringStuff.Ch15.P6_multithreading.main()[source]

AutomateTheBoringStuff.Ch15.P7_multidownloadXkcd module

Multidownload XKCD

Downloads 1400 XKCD comics much faster by using threading.

Note

Default output directory is ./xkcd.

AutomateTheBoringStuff.Ch15.P7_multidownloadXkcd.downloadXkcd(startComic: int, endComic: int) → None[source]

Download XKCD

Uses requests and bs4 to download all comics in a given range.

Parameters:
  • startComic – Comic ID number to start from.
  • endComic – Comic ID number to end at.
Returns:

None. Prints status updates and downloads comics to download directory.

AutomateTheBoringStuff.Ch15.P7_multidownloadXkcd.main()[source]

AutomateTheBoringStuff.Ch15.P8_popenFunction module

Popen function

This program uses subprocess.Popen to launch programs.

AutomateTheBoringStuff.Ch15.P8_popenFunction.main()[source]

AutomateTheBoringStuff.Ch15.P9_countdown module

Countdown

A simple countdown script that plays an alarm after a given number of seconds.

Note

AutomateTheBoringStuff.Ch15.P9_countdown.main()[source]

Module contents