Category Archives: Python 3

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.

wxPython Cookbook Artist Interview: Liza Tretyakova

I always put a lot of thought into the covers of my book. For my first book on wxPython, I thought it would be fun to do a cookbook because I already had a lot of recipes on my blog. So I went with the idea of doing a cookbook. For the cover, my first thought was to have some kind of kitchen scene with mice cooks. Then I decided that was too obvious and decided to go with the idea of an Old West cover with cowboy (or cow mice) cooking at a fire.

I asked Liza Tretyakova, my cover artist for wxPython Cookbook, to do a quick interview about herself. Here is what she had to say:

Can you tell us a little about yourself (hobbies, education, etc):

My name is Liza Tretyakova, I’m a free-lance illustrator currently working in Moscow.

Education:

  • Moscow State University, Faculty of History of Arts
  • BA(Hons) Illustration, University of Plymouth


I work as an illustrator for about 10 years. I love horses and I used to have a horse. Also I’m interested in archery. I like reading and spending a lot of time with my daughter Yara, who is 7 years old.

What motivated you to be an illustrator versus some other profession?

Since I was a child I have been drawing all the time and it just happened that I started to work as an illustrator, it turned into a profession.

What process do you go through when you are creating a new piece of art?

It is different every time, there is no specific “recipe” 🙂

Do you have any advice for someone who wants to be an illustrator?

You should try to draw every day, the more the better.

Do you have anything else you would like to say?

It was a pleasure working with you!

Thanks so much for doing the interview and for agreeing to be my illustrator for my wxPython Cookbook.

You can see more of Liza’s work on Behance.

Python 201: Intermediate Python FREE until Wednesday!

I decided it would be fun to give my latest book away for free until this Wednesday, Oct 19th. So starting today, you can get Python 201: Intermediate Python free through Gumroad or Leanpub.

If you go with Gumroad, then you will need to use the following offer code: 201free. Note that if you want to receive updates to the book, you will want to create an account and add the book to your library.

Python201_cover20160330_sm-237x300

Book Contest: Win a Copy of Python 201

I have decided to sponsor a contest for my second book, Python 201: Intermediate Python. I will be giving away 3 copies of my eBook bundle (PDF, EPUB and MOBI) and 2 copies of the paperback, which I will ship anywhere in the world. If you haven’t heard of my book, you may want to read about it here.

How You Can Win

To win your copy of this book, all you need to do is come up with a comment below highlighting the reason “why you would like to win this book”.

Duration of the contest & selection of winners

The contest is valid until Friday, Sept 16th at 11:59 p.m. CST, and is open to everyone. Winners will be selected on the basis of their comment posted. The contest will close on 09/17/2016 at 12 a.m. CST.

Python201_cover20160330_sm-237x300