Category Archives: Python 3

ReportLab Book Funded + TOC

After collating the various ideas that people have been giving me during the Kickstarter campaign, I have decided to firm up my table of contents. I had already planned to cover 80-90% or more of what was in ReportLab’s user guide, but in more depth, as I thought most of those topics should be covered in book form. The rest of the book was going to be some HOW-TO type chapters and other Python packages that work with PDFs. With that in mind, here is what the table of contents is looking like:

Part I – The ReportLab Toolkit

  • Chapter 1 – The Canvas
  • Chapter 2 – Fonts
  • Chapter 3 – PLATYPUS
  • Chapter 4 – Paragraphs
  • Chapter 5 – Tables
  • Chapter 6 – Other Flowables
  • Chapter 7 – Custom Flowables
  • Chapter 8 – Charts / Graphs
  • Chapter 9 – Other Graphics
  • Chapter 10 – PDF Special Features (Forms, Links, Encryption)
  • Chapter 11 – Bar Codes / QR Codes

Part II – Tutorials / HOW-Tos

  • Chapter 12 – Turning XML into Multipage PDFs
  • Chapter 13 – Custom headers and footers, page numbers
  • Chapter 14 – Creating a table of contents (Stretch goal) 
  • Chapter 15 – Exporting Data from PDFs (pdfminer) (Stretch goal) 
  • Chapter 16 – Filling in PDF Forms with Python (pdfforms) (Stretch goal)
  • Chapter 17 – PyPDF2 / pdfrw
  • Chapter 18 – Converting Markup to PDF (rst2pdf, html2pdf, etc) (Stretch goal)
  • Chapter 19 – pyfpdf, An Alternative to ReportLab

Note that the chapter titles are subject to change. Also note that I have marked some of the chapters as “stretch goal” chapters. They may or may not get added depending on whether or not we reach our stretch goal.

Stretch Goal(s)

My stretch goal is to hit $6000 or 500 backers. If we hit either of those, than all of the chapters above will get added. If we don’t, then I will evaluate how close we got and I may put out a survey to see which two chapters we will keep and which two will be voted out of the book.

The last thing I would like to make note of is that the first 3 chapters of the book is over 60 pages of content all by themselves, so even if I only did the first section of the book (i.e. 11 or 12 chapters), the book would still be over 200 pages in length.

If you’d like to get early access to the book, then please go check out the Kickstarter!

wxPython Recipes Book Release

I was contacted earlier this year by Apress about republishing my book, wxPython Cookbook, under their branding. I thought it might be fun to see what I could learn from a publisher so I went with them as I have enjoyed several of their books in the past. The biggest change to the book is that I ended up grouping recipes into chapters instead of having each recipe be a stand-alone chapter. I also added a few new recipes to help fill in when some chapters weren’t easily sorted into groups.

Anyway, Apress just released the book in the past couple of days:

You can find the book over on Amazon or on the Apress website. You can also see a preview of the book on Google.

You can get 20% off of the book from Apress by using the following code: wx20. This code is good on the paperback and the eBook versions of the book until June 2018.

The code for the book is hosted on Apress’s Github account. I also host a copy on Github.

Regardless, feel free to check it out. If you already bought a copy of the wxPython Cookbook, then you don’t need to get this one too since it’s basically the same thing with a bit more polish and a handful of new recipes. I have plans for some other books that I will be self-publishing hopefully in 2018, so keep an eye on the blog for news about that!

Educative Python 101 / 201 Courses on Sale

It’s that time of year again where the holidays are upon us, so I am doing a sale of some of my works. You can get Python 101 for FREE and Python 201: Intermediate Python for 50% off. Here are the coupon codes you can use:

Note that Python 101 is completely FREE with this coupon while the second course is 50% off. You can also get Python 101’s eBook for free over on Leanpub. You can also get the eBook for Python 201 for 50% off by using this link: http://leanpub.com/python201/c/py201free

All these coupons are good for one week. Thanks for your support!

ANN: Python 101 Website

After making my first book, Python 101, freely available, I have been investigating the best way to make its contents available online as well. Since I write all my books in RestructuredText, I had a few options. I ended up going with Sphinx for now, but I may end up switching to something else in the future.

Sphinx is the documentation tool used by the Python language for their documentation and it is also the backbone of Read the Docs, which is a website of documentation for 3rd party Python packages. I tried the default Sphinx theme of Alabaster, but it didn’t have the two features I most wanted:

  • Mobile friendly
  • Next / Previous buttons to make chapter navigation easy

Or at least it didn’t appear to be easy to modify to make these features available. So I ended up switching to the Read the Docs theme as it had both of those features. You can check out the book at the following URL:

http://python101.pythonlibrary.org

Educative Python Courses on Sale for PyCon!

I am putting my interactive Educative Python courses on Sale for PyCon this week. You can get Python 101 and Python 201: Intermediate Python for 50% off. Here are the coupon codes you can use:

Educative is also doing a 50% off sale on their Python 3: An interactive deep dive course which you can get with this coupon: au-pycon-deepdive.

And now for something completely different, Educative is offering a 17% off sale of their Coderust 2.0: Faster Coding Interview Preparation using Interactive Visualizations, so if you are interested in learning something a little different, now is your chance! Here’s the code for that: au-pycon-coderust

Python 101 – An Intro to IDLE

Python comes with its own code editor: IDLE (Integreted Development and Learning Environment). There is some lore that the name for IDLE comes from Eric Idle, an actor in Monty Python. An IDE is an editor for programmers that provides color highlighting of key words in the language, auto-complete, an “experimental” debugger and lots of other fun things. You can find an IDE for most popular languages and a number of IDEs will work with multiple languages. IDLE is kind of a lite IDE, but it does have all those items mentioned. It allows the programmer to write Python and debug their code quite easily. The reason I call it “lite” is the debugger is very basic and it’s missing other features that programmers who have a background using products like Visual Studio will miss. You might also like to know that IDLE was created using Tkinter, a Python GUI toolkit that comes with Python.

Continue reading Python 101 – An Intro to IDLE

Book Review: Murach’s Python Programming

I review books for the i-programmer website from time to time and they recently gave me a copy of Murach’s Python Programming by Michael Urban and Joel Murach. This book is long at almost 600 pages and it’s pretty expensive for the paperback. For those of you with short attention spans, I give you the Quick Review. For those who would like something a bit more in-depth, you will need to click through to see the rest.


Quick Review

  • Why I picked it up: In this case, because i-programming asked me to
  • Why I finished it: Because this book is well written and fairly interesting
  • I’d give it to: Someone who wants to learn Python

Continue reading Book Review: Murach’s Python Programming

New in Python: Syntax for variable annotations

Python 3.6 added another interesting new feature that is known as Syntax for variable annotations. This new feature is outlined in PEP 526. The basic premise of this PEP is take the idea of Type Hinting (PEP 484) to its next logical step, which is basically adding option type definitions to Python variables, including class variables and instance variables. Please note that adding these annotations or definitions does not suddenly make Python a statically typed language. The interpreter still doesn’t care what type the variable is. However, a Python IDE or other utility like pylint could have an annotation checker added to them that could highlight when you use a variable that you have annotated as one type and then used incorrectly by changing its type mid-function.

Let’s look at a simple example so we can see how this works:

# annotate.py
name: str = 'Mike'

Continue reading New in Python: Syntax for variable annotations

New in Python: Underscores in Numeric Literals

Python 3.6 added some interesting new features. The one that we will be looking at in this article comes from PEP 515: Underscores in Numeric Literals. As the name of the PEP implies, this basically gives you the ability to write long numbers with underscores where the comma normally would be. In other words, 1000000 can now be written as 1_000_000. Let’s take a look at some simple examples:

>>> 1_234_567
1234567
>>>'{:_}'.format(123456789)
'123_456_789'
>>> '{:_}'.format(1234567)
'1_234_567'

The first example just shows how Python interprets a large number with underscores in it. The second example demonstrates that we can now give Python a string formatter, the “_” (underscore), in place of a comma. The results speak for themselves.

The numeric literals that include underscores behave the same way as normal numeric literals when doing calculations:

>>> 120_000 + 30_000
150000
>>> 120_000 - 30_000
90000

The Python documentation and the PEP also mention that you can use the underscores after any base specifier. Here are a couple of examples taken from the PEP and the documentation:

>>> flags = 0b_0011_1111_0100_1110
>>> flags
16206
>>> 0x_FF_FF_FF_FF
4294967295
>>> flags = int('0b_1111_0000', 2)
>>> flags
240

There are some notes about the underscore that need to be mentioned:

  • You can only use one consecutive underscore and it has to be between digits and after any base specifier
  • Leading and trailing underscores are not allowed

This is kind of a fun new feature in Python. While I personally don’t have any use cases for this in my current job, hopefully you will have one at yours.