Archive for March, 2014

I just wanted to drop a quick note that the Python 101 book is now available for Pre-order here. Currently you will receive the draft versions of the book as they become available. Right now, Parts I and II have been released which amounts to approx. 115 pages of content.

mousecovertitlejpg_sm2

You can read more about the book below: (more…)

When you’re first starting out as a Python programmer, you don’t think about how you might need to install an external package or module. But when that need appears, you’ll want to know how to in a hurry! Python packages can be found all over the internet. Most of the popular ones can be found on the Python Package Index (PyPI). You will also find a lot of Python packages on github, bitbucket, and Google code. In this article, we will be covering the following methods of installing Python packages:

  • Install from source
  • easy_install
  • pip
  • Other ways to install packages

(more…)

The lxml.objectify sub-package is extremely handy for parsing and creating XML. In this article, we will show how to create XML using the lxml package. We’ll start with some simple XML and then try to replicate it. Let’s get started! (more…)

There are a couple of ways to create Microsoft Excel spreadsheets with Python. You can use PyWin32′s win32com.client method, which was discussed in an old article a number of years ago or you could use the xlwt package. We’ll be looking at the latter in this article. You will learn how to create an Excel spreadsheet with multiple worksheets and how to create styled cells. Let’s get started! (more…)

The Python 101 book campaign finished today. I am now well funded to create the book and get all the artwork done. I think I may try to get additional illustrations too. While we didn’t hit the next stretch goal, I plan to go ahead and work on screencasts anyway. As I mentioned previously, I most likely won’t start on those until after I’ve finished writing the book. I have received lots of positive comments about the book so far and I hope to put out a product that you will find useful.

I will be sending out Part I as soon as I can after Kickstarter transfers the funds. You will receive a survey asking for your email address. I will probably be sending a survey out to those who bought t-shirts and such too.

Thanks a lot for all your support. I am very grateful.

Code profiling is an attempt to find bottlenecks in your code. Profiling is supposed to find what parts of your code take the longest. Once you know that, then you can look at those pieces of your code and try to find ways to optimize it. Python comes with three profilers built in: cProfile, profile and hotshot. According to the Python documentation, hotshot “no longer maintained and may be dropped in a future version of Python”. The profile module is a pure Python module, but adds a lot of overhead to profiled programs. Thus we will be focusing on cProfile, which has an interface that mimics the profile module. (more…)

Python comes with its own debugger module that is named pdb. This module provides an interactive source code debugger for your Python programs. You can set breakpoints, step through your code, inspect stack frames and more. We will look at the following aspects of the module:

  • How to start the debugger
  • Stepping through your code
  • Setting breakpoints

Let’s start by creating a quick piece of code to attempt debugging with. (more…)

There are under 2 days left in the book campaign! I think that’s pretty exciting. I hope you do too!

I’ve been busy writing the new Part 3 lately. I only have two more chapters to go before it’s done. My hope is that Part 3 will be done by the end of the week.

I have also come up with a fun little script that can put my book together for me. Today it dawned on me that this little program would be a good illustration for my readers about how to tackle a project and break it into more manageable pieces. So I’ll be adding a chapter or two somewhere in the book about that as some of my backers have already mentioned that they would like to know how to do this sort of thing.

Thanks for your support!

Python 3.4 released today (2014-03-17) and includes a lot of neat stuff. According to the Python Insider, these are the major changes / additions:

  • PEP 428, a “pathlib” module providing object-oriented filesystem paths
  • PEP 435, a standardized “enum” module
  • PEP 436, a build enhancement that will help generate introspection information for builtins
  • PEP 442, improved semantics for object finalization
  • PEP 443, adding single-dispatch generic functions to the standard library
  • PEP 445, a new C API for implementing custom memory allocators
  • PEP 446, changing file descriptors to not be inherited by default in subprocesses
  • PEP 450, a new “statistics” module
  • PEP 451, standardizing module metadata for Python’s module import system
  • PEP 453, a bundled installer for the *pip* package manager
  • PEP 454, a new “tracemalloc” module for tracing Python memory allocations
  • PEP 456, a new hash algorithm for Python strings and binary data
  • PEP 3154, a new and improved protocol for pickled objects
  • PEP 3156, a new “asyncio” module, a new framework for asynchronous I/O

I can’t wait to try out some of these new modules and see what new things I can add to my bag of tricks. Go download your copy today!

 

Python includes a couple of modules for testing in its standard library: doctest and unittest. We will be looking at doctest in this article. The doctest module will search for pieces of text in your code that resemble interactive Python sessions. It will then execute those sessions to verify that they work exactly as written. This means that if you wrote an example in a docstring that showed the output with a trailing space or tab, then the actual output of the function has to have that trailing whitespace too. Most of the time, the docstring is where you will want to put your tests. The following aspects of doctest will be covered:

  • How to run doctest from the terminal
  • How to use doctest inside a module
  • How to run a doctest from a separate file

Let’s get started! (more…)