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…)

kivy_poster_1

Kivy is an open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps. The Kivy organization is organizing its second application development contest.! This is a great chance for new and experienced users to show off their skills and compete for prizes. Entries will be judged on a range of criteria accessible to both new and experienced programmers, so don’t be afraid to dive in! For more information, visit http://kivy.org/#contest

Over the weekend, I finished setting up a website for my upcoming book, Python 101. I discovered that www.python101.com is owned by squatters, so I got www.python101.org instead. It will redirect to http://python101.pythonlibrary.org because I think the book should be a part of Python Library while maintaining its independence.

There isn’t much content on the site yet, but I hope to be adding more as the book’s launch date approaches. For those of you who are interested, the Kickstarter Campaign has only 3 more days to go, so if you want to contribute, you’ll need to hurry!

We only have five more days before the end of the campaign, so I thought it would be nice to share a couple chapters from the book. You can download the introduction along with chapters 1 and 2 here.

I have been working on the new section of the book since it is now the new Part III. It is coming along pretty well. My illustrator has been busy creating some new art for the book. I’ll be sharing that soon.

Thanks a lot for your support and have a great weekend!

The wxPython Google Group was discussing different methods of catching exceptions in wxPython the other day. If you use wxPython a lot, you will soon realize that some exceptions are difficult to catch. The wxPython Wiki explains why. Anyway, the fellows on the list were recommending the use of sys.excepthook. So I took one of the methods they mentioned and created a little example: (more…)

Python decorators are really cool, but they can be a little hard to understand at first. A decorator in Python is a function that accepts another function as an argument. The decorator will usually modify or enhance the function it accepted and return the modified function. This means that when you call a decorated function, you will get a function that may be a little different that may have additional features compared with the base definition. But let’s back up a bit. We should probably review the basic building block of a decorator, namely, the function. (more…)

Reportlab is a very flexible PDF creation package for Python. You can layout your documents using absolute positioning or by using Flowable objects, such as a Paragraph, a Table or Frame. You can even mix the two together! In this article, we will be looking at how to create some custom Flowables. For example, what do you do if you need to add a line to demarcate the start of a new section in your document? There isn’t really a built-in Flowable for that, so we’ll design our own. We will also design a flowable that has a line and a box with text inside of it.

Let’s get started! (more…)

There’s a Python book contest going on over on the Bite Sized Python Tips blog. You can get one of 3 copies of the book Tkinter GUI Application Development by Bhaskar Chaudhary. I reviewed this book late last year and found it be a really interesting book. I think it will give you lots of good ideas to try in developing your own GUI applications. Now’s your chance to get a copy of this neat book!

The other day someone was asking a lot of questions on StackOverflow about how to work with wizards in wxPython. You can read the two original questions here and here. The code we’ll be looking at in this example is what I used to answer the questions on Stack. The primary question was how to disable the Next in a wxPython wizard. (more…)

« Previous PageNext Page »