Redirecting stdout seems to be a pretty common request on the wxPython users group, so I decided to see how easy it would be to do it with Tkinter. The typical use case for redirecting stdout or stderr is that you are calling some other process (like ping or tracert) and you want to catch what it’s doing to put it into your UI. Usually you can just use Python’s subprocess module and call its communicate() method to access the data. Then you can just print it to stdout and it will magically appear in your UI’s widget of choice.

Our finished user interface will look something like the following:


Let’s find out how to do this with Tkinter: (more…)

I’ve been using wxPython for quite a while now and I see certain questions come up on a fairly frequent basis. One of the popular ones is how to ask the user for their credentials before loading up the rest of the application. There are several approaches to this, but I am going to focus on a simple solution as I believe this solution can be used as the basis for more complex solutions.

Basically what we want to happen is for the user to see a login dialog where they have to enter their username and password. If they enter it correctly, then the program will continue to load and they’ll see the main interface. You see this a lot on websites with a common use case being web email clients. Desktop applications don’t include this functionality as often, although you will see it for’s application and for law enforcement software. We will be creating a dialog that looks like this:

wxLogin.png (more…)

Yesterday, Philip Guo made the claim that Python is now the most popular introductory teaching language at top U.S. universities on the Communications of the ACM blog. I came across this information via Planet Python’s redistribution of Vasudev Ram’s blog post on the subject.

If this is true, then I think this is really cool. Python is easy to learn and quite capable of most programming tasks. I’ve been using it for over 8 years now in all kinds of settings and Python has almost always come through for me. Anyway, check out the article and feel free to leave some feedback.

Packt Publishing recently asked me if I would be interested in letting my readers know about a sale that they are doing right now. Most of the time, I avoid marketing to my readers, but Packt has a lot of Python ebooks for sale this week that I think you might find useful. Here is their press release (plus links to my reviews of the book, if applicable):


Packt Publishing celebrates 10 years with a special $10 offer


It has been 10 years since Packt Publishing embarked on its mission to deliver effective learning and information services to IT professionals. In that time, it has published over 2000 titles and helped projects become household names, awarding over $400,000 through its Open Source Project Royalty Scheme.

To celebrate this huge milestone, Packt is offering all of its eBooks and Videos at just $10 each – this promotion covers every title and customers can stock up on as many copies as they like until July 5th If you’ve already tried a Packt title in the past, you’ll know this is a great opportunity to explore what’s new and maintain your personal and professional development. If you’re new to Packt, then now is the time to try their extensive range – Within their 2000+ titles range, you’ll find the knowledge you really need , whether that’s specific learning on an emerging technology or the key skills to keep you ahead of the competition in more established tech fields.’

Some of the Python books that you can check out:

• Kivy Interactive Applications in Python (review)

• Tkinter GUI Application Development HOTSHOT (review)

• Instant Flask Web Development (review)

• web2py Application Development Cookbook (review)

• Numpy 1.5 Beginner’s Guide (review)

• MySQL for Python (review)

• Python Multimedia Application Beginner’s Guide (review)

• Python 3 Object Oriented Programming (review)

More information is available at:

Last week, DZone contacted me to ask if I would like to be featured in their “Dev of the Week” series. In other words, they wanted to do a short interview with me. The interview went live yesterday. You can read it here, if you like:

I don’t know why the link is on their java sub-domain, but needless to say, I talked about Python in almost all of my answers. I wouldn’t be posting a link to my interview on my blog if it didn’t have something to do with Python. Anyway, if you’d like to learn a little more about me, I thought you might find that interesting.

Last year there was an Indiegogo crowdfunding campaign in support of PyDev, the Python IDE plugin for Eclipse. It was put on by the primary developer of PyDev, Fabio Zadrozny. As a part of that campaign, Fabio also created LiClipse.

Anyway, Fabio is at it again with a new crowdfunding campaign. You can read about it here. Fabio has two targets for this campaign. The first is adding the following features to PyDev:

  • Allow preferences which are currently global to be configured per-project.
  • Provide a proper way to export/import PyDev settings to a new workspace.
  • Suport for namespace packages in code-completion.
  • Provide a way to auto-document types as well as checking existing types in docstrings when doing a test run.
  • Allow running an external pep8 linter (to support newer versions of
  • Show vertical lines for indentation.
  • Attach debugger to running process (although some caveats apply and under certain circumnstances this may not be possible).
  • Other requests to be defined based on community input as funding allows.

The second is, in my opinion, a bit more interesting. Fabio is planning on writing a profiler for PyDev that can also work outside of PyDev using Python and Qt. He has a list of features for the profiler listed in his campaign. It sounds pretty interesting. It should also be noted that PyDev and the proposed profiler will be open source, so you can always check out how the code works behind the scenes.

If you think either of these items sound interesting, then you should consider supporting Fabio in his endeavors.

This contest is now over

I have decided to sponsor a contest for my first book, Python 101. I will be giving away 3 copies of my eBook bundle (PDF, EPUB and MOBI) and 1 copy of the paperback, which I will ship anywhere in the world. If you haven’t heard of my book, you may want to read this other post.

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 for 2 weeks, and is open to everyone. Winners will be selected on the basis of their comment posted. The contest will close on 07/04/2014 at 9 a.m. CST.


eGenix announced this week that they were releasing an “open source, one file, no installation version of Python”. You can read their entire announcement in their press release here. If you want to check out the actual product, you can get it at the following URL:

This is a Unix-based Python and they state that they only provide Linux, FreeBSD and Mac OS X, as 32- and 64-bit versions, so if you’re a Windows guy, you’re out of luck. I think one of the coolest aspects of this tool is that it’s 11MB for Python 2 and 13MB for Python 3, but it still supports most Python applications and code that you’ve written. If you write a lot of code that depends on 3rd party utilities, than I don’t think PyRun will be very helpful to you. But if you depend mostly on Python’s standard library, than I can see this as a very handy tool.

An alternative to PyRun would be Portable Python which provides a large number of 3rd party libraries that are baked in with the standard library. I’ve used Portable Python in several applications of my own where I didn’t want to install Python itself. Anyway, I hope you find this information useful in your own endeavors.

Every once in a while, I run into a situation where I need dummy data to test my code against. If you need to do tests on a new database or table, you will run into the need for dummy data often. I recently came across an interesting package called Faker. Faker’s sole purpose is to create semi-random fake data. Faker can create fake names, addresses, browser user agents, domains, paragraphs and much more. We will spend a few moments in this article demonstrating some of Faker’s capabilities. (more…)

Recently I ran into an issue where an application that calls Python would insert int into Python’s namespace, which overwrites Python’s built-in int function. Since I have to use the tool and I needed to use Python’s int function, I needed a way around this annoyance.

Fortunately, this is fairly easy to fix. All you need to do is import int from __builtin__ and rename it so you don’t overwrite the inserted version:

from __builtins__ import int as py_int

This gives you access to Python’s int function again, although it is now called py_int. You can name it whatever you like as long as you don’t name it int.

The most common circumstance where one shadows builtins or other variables is when the developer imports everything from a package or module:

from something import *

When you do an import like the one above, you don’t always know what all you have imported and you may end up writing your own variable or function that shadows one that you’ve imported. That is the main reason that importing everything from a package or module is so strongly discouraged.

Anyway, I hope you found this little tip helpful. In Python 3, the core developers added a builtins module basically for this very purpose.

« Previous PageNext Page »