Tag Archives: Python

PyDev of the Week: R. David Murray

This week we welcome R. David Murray (@rdavidmurray) as our PyDev of the Week. Mr. Murray is a core developer of the Python language and is currently maintainer of the email module. He has a Python blog, although it hasn’t been updated in a while. You might want to check out his Github profile to see some of the other projects he is working on. Let’s spend some time getting to know our fellow Pythonista!

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

In my youth I thought I wanted to be a Particle Physicist.  Went to the University of Pennsylvania to study physics, and indulged my second love (computers, which at that time were just at the IBM mainframe/TRS 80 stage) by getting a work study job in the Physics Department computing facility.  By my second year there I had decided that Physics itself was just too…messy, but that I loved the math and especially working with computers.  So I graduated with a BA in computer mathematics, and have proceeded to use the computer half and not the math half for most of my career.

Outside of work, I love reading Science fiction and Contra Dancing which my wife and I do twice a week on average.  It keeps me healthy and feeling younger (I find the (live) music wonderful, and it is a dance form that attracts all ages, which is psychologically beneficial, and as an added benefit it is great exercise).

Continue reading PyDev of the Week: R. David Murray

Python 201 – super

I’ve written about super briefly in the past, but decided to take another go at writing something more interesting about this particular Python function.

The super built-in function was introduced way back in Python 2.2. The super function will return a proxy object that will delegate method calls to a parent or sibling class of type. If that was a little unclear, what it allows you to do is access inherited methods that have been overridden in a class. The super function has two use cases. The first is in single inheritance where super can be used to refer to the parent class or classes without actually naming them explicitly. This can make your code more maintainable in the future. This is similar to the behavior that you will find in other programming languages, like Dylan’s *next-method*.

The second use case is in a dynamic execution environment where super supports cooperative multiple inheritance. This is actually a pretty unique use case that may only apply to Python as it is not found in languages that only support single inheritance nor in statically compiled languages.

super has had its fair share of controversy even among core developers. The original documentation was confusing and using super was tricky. There were some who even labeled super as harmful, although that article seems to apply more to the Python 2 implementation of super then the Python 3 version. We will start out this chapter by looking at how to call super in both Python 2 and 3. Then we will learn about Method Resolution Order.

Continue reading Python 201 – super

Python 101: An Intro to Benchmarking your code

What does it mean to benchmark ones code? The main idea behind benchmarking or profiling is to figure out how fast your code executes and where the bottlenecks are. The main reason to do this sort of thing is for optimization. You will run into situations where you need your code to run faster because your business needs have changed. When this happens, you will need to figure out what parts of your code are slowing it down.

This chapter will only cover how to profile your code using a variety of tools. It will not go into actually optimizing your code. Let’s get started!

Continue reading Python 101: An Intro to Benchmarking your code

PyDev of the Week: Wesley Chun

This week we welcome Wesley Chun as our PyDev of the Week! Wesley Chun, MSCS, is author of Prentice Hall’s bestselling “Core Python” series (corepython.com), the “Python Fundamentals” companion videos, co-author of “Python Web Development with Django” (withdjango.com), and has written for Linux Journal, CNET, and InformIT. In addition to being an engineer at Google, he runs CyberWeb (cyberwebconsulting.com), a consultancy specializing in Python training. Wesley has over 25 years of programming, teaching, and writing experience, including more than a decade of Python. While at Yahoo!, helped create Yahoo!Mail using Python. Wesley holds degrees in Computer Science, Mathematics, and Music from the University of California. He is based in Silicon Valley and can be reached on Twitter (twitter.com/wescpy) or Google+ (google.com/+WesleyChun). Let’s spend a few minutes getting to know him better!




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


I’ve been a software engineer by profession, coding in Python, JavaScript, and a few others, at big companies as well as startups. I’m currently at Google, a nice blend of both worlds. I enjoy helping the next generation of developers get up-to-speed on the latest technologies and best practices with the least amount of friction, meaning that in addition to coding, I also teach technology, publish books & blogposts, and give talks at conferences. Stuff I like to do away from the keyboard include family time, piano, personal finance, world travel, physical fitness (cycling, yoga, biking, basketball), poker, and learning a few words in as many languages as I can.


Continue reading PyDev of the Week: Wesley Chun

Python 101: How to timeout a subprocess

The other day I ran into a use case where I needed to communicate with a subprocess I had started but I needed it to timeout. Unfortunately, Python 2 does not have a way to timeout the communicate method call so it just blocks until it either returns or the process itself closes. There are lots of different approaches that I found on StackOverflow, but I think my favorite was using Python’s threading module’s Timer class:

import subprocess
from threading import Timer
kill = lambda process: process.kill()
cmd = ['ping', 'www.google.com']
ping = subprocess.Popen(
    cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
my_timer = Timer(5, kill, [ping])
    stdout, stderr = ping.communicate()

Continue reading Python 101: How to timeout a subprocess

PyDev of the Week: Ed Leafe

This week we welcome Ed Leafe (@EdLeafe) as our PyDev of the Week! Ed is one of the co-creators of the Dabo Application Framework, which is a neat wrapper around wxPython and is aimed at building database driven applications, although you can use it for more than that. Ed also authors a fun tech blog. Let’s take a few minutes to get to know him better!

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

I’ve had many careers, with software development being the latest and longest one. While my degree is in Biochemistry, CS was a minor, so computers have always been somewhere in the picture. For example, I’ve had 3 startup businesses, but they were all in the construction field, and unlike today, we had to be profitable from the start. But to tie that to today, I partnered with an architect (an actual licensed building architect, not a self-important programmer) to come up with 3-D visualizations of decks, additions, etc, that used photographs as a base with a CAD program drawing on top. The CAD items were linked to a database, so we could generate both a parts list and an estimate directly from the drawing. If the customer wanted to change something, such as add a window, we made the change on the drawing, and the estimate updated accordingly. Oh, and this was in the 1989-91 time frame, running on a Mac SE.

I’m also a photographer. I exhibited quite a bit when I was younger, and am starting to get back into it. Here’s some of my recent work: https://goo.gl/FR7PwX

Continue reading PyDev of the Week: Ed Leafe

PyDev of the Week: Karsten Hilbert

This week we welcome Karsten Hilbert as our PyDev of the Week! Karsten took over the GNUmed project, which is a an open source electronic medical record program written mostly in Python. Let’s take a few moments to get to know him better!

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

I am a Medical Doctor in Germany.

Why did you start using Python?

The OSS project I got involved with (GNUmed) was written in Python. When I took over the balance of ease-of-use, clarity and batteries-included felt just right so I stayed with it.

Continue reading PyDev of the Week: Karsten Hilbert

Python 201 Book Writing Update: Part 1 is Ready

I’ve been busily working on my second book, Python 201: Intermediate Python. In part one of the book, there are 10 chapters. I recently finished up the last chapter for that part of the book. While I have some tweaks I want to do to a couple of the chapters in this part of the book, I’m going to leave them alone for now so I can get part 2 done. Then I’ll be going back to part 1 to do some updates. This also allows the early adopters time to read the first chapters and send me messages about typos or bugs.

For those of you who didn’t get in on the Kickstarter for the book, the first 10 chapters are as follows:

  • Chapter 1 – The argparse module
  • Chapter 2 – The collections module
  • Chapter 3 – The contextlib module (Context Managers)
  • Chapter 4 – The functools module (Function overloading, caching, etc)
  • Chapter 5 – All about imports
  • Chapter 6 – The importlib module
  • Chapter 7 – Iterators and Generators
  • Chapter 8 – The itertools module
  • Chapter 9 – The re module (An Intro to Regex in Python)
  • Chapter 10 – The typing module (Type Hinting)

There are currently 71 pages in the book so far in my Gumroad edition and over 80 pages in the Leanpub version. Leanpub is generated differently which means they use different fonts and font sizes, which is why that version has more pages.  Regardless, the book is coming along well and is still on track for a September, 2016 release!

Python 201: An Intro to Iterators and Generators

You have probably been using iterators and generators since you started programming in Python but you may not have realized it. In this article, we will learn what an iterator and a generator are. We will also be learning how they are created so we can create our own should we need to.


An iterator is an object that will allow you to iterate over a container. The iterator in Python is implemented via two distinct methods: __iter__ and __next__. The __iter__ method is required for your container to provide iteration support. It will return the iterator object itself. But if you want to create an iterator object, then you will need to define __next__ as well, which will return the next item in the container.

Note: In Python 2, the naming convention was slightly different. You still needed __iter__, but __next__ was called next.

To make things extra clear, let’s go over a couple of definitions:

  • iterable – an object that has the __iter__ method defined
  • iterator – an object that has both __iter__ and __next__ defined where __iter__ will return the iterator object and __next__ will return the next element in the iteration.

Continue reading Python 201: An Intro to Iterators and Generators

PyDev of the Week: Mark Lutz

This week we have the honor of welcoming Mark Lutz as our PyDev of the Week. Mark is the author of the first Python book ever, Programming Python. He has also authored Learning Python and the Python Pocket Reference, all three of which were with O’Reilly publishing. Rather than rehash more of his background, let’s just jump into the interview so we can learn more about Mark Lutz!


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

I’m a software engineer, a Python book author and trainer, and one of the people who helped Python rise to the prominence it enjoys today.

I’ve been working in the software field for 3 decades, and earned BS and MS degrees in computer science from the University of Wisconsin. Back when I was being paid to do development, I worked on compilers for supercomputers and CAD systems, and large-scale applications at assorted start-ups.

Since quitting my “day job” two decades ago, I’ve been teaching Python classes in North America and Europe, and writing Python books that have sold over half a million units and span 11k published pages. To put that in perspective, back-of-the-envelope calculations suggest that the paper units of my books sold comprise about 650 tons (and counting).

If you’re interested in more details, check out my formal bio page at http://learning-python.com/books/formalbio.html.


Continue reading PyDev of the Week: Mark Lutz