Skip to content
Branch: master
Find file History
Latest commit 295c1b0 Aug 14, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Amazon Move some stuff Jun 19, 2019
convert Tweak some things - move to book3 Jul 10, 2016
cover Add cover files - note a need to unzip May 28, 2018
figs2 Tweak some things - move to book3 Jul 10, 2016
html Fix issue #218 from ck39 Aug 14, 2019
kindle New version Jun 23, 2017
notes Tweak some things - move to book3 Jul 10, 2016
trinket Updates Jun 19, 2019
zipbook Fix one typo :) Sep 9, 2018
zips Fix one typo :) Sep 9, 2018
00-cover.old Tweak some things - move to book3 Jul 10, 2016
01-intro.mkd Update 01-intro.mkd Jul 5, 2019
02-variables.mkd Updates Jul 21, 2019
03-conditional.mkd Remove overfill badness May 22, 2018
04-functions.mkd Standardize backticks Apr 11, 2018
05-iterations.mkd Remove heading May 22, 2018
06-strings.mkd Remove overfill badness May 22, 2018
07-files.mkd Update 07-files.mkd Jan 17, 2019
08-lists.mkd Python 2 sneaked through in a comment - thanks @upyesp Aug 4, 2019
09-dictionaries.mkd Update bashe on Coursera thread. Jul 21, 2019
10-tuples.mkd Fix one typo :) Sep 9, 2018
11-regex.mkd Fix issue #218 from ck39 Aug 14, 2019
12-network.mkd Typos from #203 Jul 21, 2019
13-web.mkd Updates Jun 19, 2019
14-objects.mkd fix typo Oct 24, 2018
15-database.mkd Changed filenames xx.sqlite3 to xx.sqlite Mar 3, 2019
16-viz.mkd Update 16-viz.mkd Jun 27, 2018
A0-preface.mkd Fix typos Apr 20, 2018
AA-contrib.mkd Tweak Nov 22, 2016
AB-copyright.mkd
README.md Small updates to book text Aug 28, 2017
book.sh Update the instructions for Chinese Jun 24, 2017
consoles.py Tweak some things - move to book3 Jul 10, 2016
createspace.sty Tweak some things - move to book3 Jul 10, 2016
epub-metadata.txt Add support for auto-mobi creation Jul 10, 2016
epub.css Remove blue Jun 23, 2017
htmlbook.sh Tune down the htmlbook.sh script Jul 8, 2017
index.htm Tweak Nov 22, 2016
mgrep.sh Tweak some things - move to book3 Jul 10, 2016
mhack.py Tweak some things - move to book3 Jul 10, 2016
mhack.sh Tweak some things - move to book3 Jul 10, 2016
pfe.zip Tweak some things - move to book3 Jul 10, 2016
phpbook.sh Major leap forward on HTML books. Jul 8, 2017
post-html.py Major leap forward on HTML books. Jul 8, 2017
pre-html.py Tweak some things - move to book3 Jul 10, 2016
template.latex Increase TOC width Apr 12, 2018
testverbatim.txt Tweak some things - move to book3 Jul 10, 2016
texpatch.py Tweak some things - move to book3 Jul 10, 2016
trinketbook.sh Tweak some things - move to book3 Jul 10, 2016
typos.py Tweak some things - move to book3 Jul 10, 2016
verbatim.py Change the URL to py4e.com, typoes Aug 31, 2016
zipbook.sh Moar progress Jul 8, 2017

README.md

Python for Everybody

These *.mkd files are now the master files for the book (i.e. I will not run the conversion any more).

To produce the PDF of the book, you will need to install LaTeX on your system. For Debian-derived (Ubuntu, Mint, etc.) Linux:

sudo apt-get install texlive-full
sudo apt-get install pandoc

For Macintosh,

https://www.tug.org/mactex/
https://www.tug.org/mactex/mactextras.html

To produce the book run

bash book.sh

The output bash book.sh is in the file x.pdf and x.epub.

Note that the build scripts require Python 2

Build Server

There is a continuous build server that I have on Digital Ocean that builds the PDF and epub versions of the book every hour or so.

http://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.pdf
http://do1.dr-chuck.com/pythonlearn/EN_us/pythonlearn.epub

Just check in changes and these files will update.

This server also rebuilds any translations every hour or so.

Alternate Build Scripts

In addition to the official book.sh1, there are other build scripts that make alternate versions of the book. If you make changes to the content, you should run all these scripts and check it all into github so it ends up online.

  • phpbook.sh will make an html/php verion of the book that is an extension of this site in ../html3 - this is then checked into github.

  • htmlbook.sh will make an html verion of the book, with interactive examples embedded in trinkets. These files are in books/html if you want to download or view them.

  • zipbook.sh will make two html versions of the book with Trinket branding, one with interactive examples (that require an internet connection to work) and one with syntax highlighted code blocks for completely offline viewing. A zip containing these is at /book/zips/pfe.zip if you'd just like to download it.

  • trinketbook.sh will make the nunjucks template that we use to host the book at books.trinket.io. This is likely not of use to you unless you're looking for an example of how to get the book source into your own templating language. If you'd like to see the output of this script it's in books/trinket/pfe. Also updates ../trinket3.

If you'd like to make your own build script, you can use these as examples. If your build script might have use to others, consider contributing it in a pull request. Note that each build script plays nicely with the others and the represent parallel workflows. Please don't alter any of the python scripts that are used by another script if you intend on contributing a new script.

KindleGen

The book.sh script will generate the x.mobi file is KindleGen is in the path:

https://www.amazon.com/gp/feature.html?docId=1000765211

For Linux:

curl -O http://kindlegen.s3.amazonaws.com/kindlegen_linux_2.6_i386_v2_9.tar.gz
tar xfv kindlegen_linux_2.6_i386_v2_9.tar.gz 
cp kindlegen /usr/local/bin

Createspace

Just take the x.pdf and x.mobi files and copy them into the createspace folder, adding a date in the filename as version and then upload them to createspace ins kindle publishing.

Chinese Version

If you are building the file for Chinese, touch the file

touch .chinese

So it runs LaTeX in a way to produce chinese documents.

Install the 'Noto Serif CJK SC' Font. Download from here and unzip:

https://noto-website.storage.googleapis.com/pkgs/NotoSerifCJK.ttc.zip

You should get a file like NotoSerifCJK.ttc.

On Mac copy the file to ~/Library/Fonts and rebuild font cache:

sudo atsutil databases -remove

On Linux put them in /usr/share/fonts:

[ -d /usr/share/fonts/opentype ] || sudo mkdir /usr/share/fonts/opentype
[ -d /usr/share/fonts/opentype/noto ] || sudo mkdir /usr/share/fonts/opentype/noto
sudo mv NotoSerifCJK.ttc /usr/share/fonts/opentype/noto
sudo fc-cache -f -v

Strange Note: If you are running on a small memory linux system, you may encounter the error "I can't write on file test.pdf'" - turns out this is xelatex` running out of RAM - this fixed it.

dd if=/dev/zero of=/var/512mb.swap bs=1M count=512
mkswap /var/512mb.swap
swapon /var/512mb.swap

Ref: https://tex.stackexchange.com/questions/16801/xelatex-i-cant-write-on-file-test-pdf

Contributing

If you want to contribute, feel free to fork the pythonlearn repository and send me pull requests.

https://github.com/csev/py4e

We can also use the issue tracker to coordinate if that helps.

/Chuck

You can’t perform that action at this time.