Hi, I'm Daniel Greenfeld, and welcome to my blog. I write about Python, Django, and much more.

Hola, Argentina!

Wednesday, August 13, 2014 (permalink)

I'll be arriving in Argentina on August 14th. I'll be speaking at PyDay Mendoza on August 15th, and sprinting on August 16th on something Audrey and I named the "new library sprint" (more details to come). On August 22nd, I'll be speaking at the combined Buenos Aires ...

Read more ...

Want to work for Eventbrite? (part 2)

Wednesday, July 23, 2014 (permalink)

For various reasons I had to change some things about my Eventbrite test. The new version is listed here and the previous blog post has been updated:

104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 115, 116, 46, 103, 105, 116, 104, 117,
98, 46, 99, 111, 109 ...
Read more ...

Want to work for Eventbrite?

Wednesday, July 23, 2014 (permalink)

Join me, Andrew Godwin (South, Django migrations), Simon Willison (co-founder of Django, co-founder of Lanyrd), and many other talented people at Eventbrite. We have great challenges, the kind that inspire you to rise to the occasion. We need you to help us overcome them.

I should mention that Eventbrite is ...

Read more ...

cached-property: Don't copy/paste code

Tuesday, July 01, 2014 (permalink)

In Python, the @cached_property decorator is a really nice piece of code. What it does is it caches the result of a property call. The cached result will persist as long as the instance does, so if the instance is passed around and the function subsequently invoked, the cached result ...

Read more ...

Jinja2 Quick Load Function

Thursday, June 12, 2014 (permalink)

It seems like that for every few weeks I find myself needing to generate something out of a template while working outside a framework. For this task, my preferred solution is Jinja2. I've used Jinja2 to generate HTML, code, and text. If I were brave enough I would even ...

Read more ...

Python Partials are Fun!

Thursday, April 24, 2014 (permalink)

Writing reusable code is a good thing, right? The trick is to do so in a way that makes your life and those of others easier, but to do so in a very clear and maintainable way. Recently I've been playing around with Python's functools.partial function, which ...

Read more ...

Beginner's Guide to PyCon 2014

Saturday, April 05, 2014 (permalink)

New to Python and/or conferences and attending the upcoming PyCon 2014 in Montreal, Canada? Or is this your first conference? Or perhaps your first conference longer than a weekend?

Hoping to get the most out of joining thousands of Python enthusiasts?

No worries! This guide will aid you in ...

Read more ...

Docstrings and Various Python Objects

Wednesday, March 05, 2014 (permalink)

Early in my journeys with Python I struggled with understanding the purpose and use of lambda functions. When I finally understood them I was disappointed by their lack of docstrings. For that reason, and various other shortcomings, I went back to standard functions. Also, for what it's worth, I ...

Read more ...

awesome-slugify: Human-readable URL slugs from any string (part 2)

Wednesday, January 22, 2014 (permalink)

In my previous blog post I covered using awesome-slugify to capture slugs in both ASCII and unicode. Today I'm covering the definition custom language slugify translation functions.

Defining Custom Language slugify Translation Functions

For those times we need ASCII representation of unicode characters, we can't always use the ...

Read more ...

awesome-slugify: Human-readable URL slugs from any string

Tuesday, January 21, 2014 (permalink)

note: The introduction mentions Django and Plone. However, this is not an article about Django or Plone.

Introduction

Years ago, when I was working with Plone at NASA, one thing I dreaded was when content editors would copy-and-paste from Microsoft Word into the title bar. All kinds of funny characters ...

Read more ...

pytest: no-boilerplate testing (part 3)

Friday, January 17, 2014 (permalink)

In my previous blog post I covered writing exception-based assertions and fixtures. Today I'm going to close things out by demonstrating how to change the behavior of pytest and how to integrate it with Django and setup.py.

Changing the Behavior of pytest

When pytest is called, either via ...

Read more ...

pytest: no-boilerplate testing (part 2)

Thursday, January 16, 2014 (permalink)

In my previous blog post I covered test discovery and writing basic tests using pytest. Today I'm going to cover a few more features that I really enjoy: raises and fixtures.

The Intuitively Named raises context manager

When using pytest, you can assert whether or not an exception occurred ...

Read more ...

pytest: no-boilerplate testing

Wednesday, January 15, 2014 (permalink)

When I first encountered Holger Krekel's pytest this summer on Jeff Knupp's blog I felt like I had been living under a rock for years. I've been using Python's unittest framework since 2006 and nose to find tests since 2008, but here was another test framework ...

Read more ...

New Year's Meme 2013

Tuesday, December 31, 2013 (permalink)

Inspired by Alex Clark's meme, here is my own entry into this end-of-year fun.

What’s the Coolest Thing You Discovered This Year?

Alex had his own focused on Python applications, frameworks, and libraries. Me, I'm going for a more general approach. This year I discovered:

LaTeX

That ...

Read more ...

Exceptions as Decorator Arguments

Tuesday, December 24, 2013 (permalink)

I wanted to see if I could have an exception as a decorator argument. Here is what I came up with:

import functools

class MyGoof(Exception):
    pass

def pass_goof(exception):
    def decorator(test_func):
        @functools.wraps(test_func)
        def wrapper(*args, **kwargs):
            try:
                return test_func(*args, **kwargs)
            except exception as e:
                return ...
Read more ...

Python Indie Bundle Cyber Monday Sale

Monday, December 02, 2013 (permalink)

I've joined forces with Matt Harrison and Audrey Roy to put together the first ever Python Indie Bundle sale!

This bundle includes the following e-book bundles (PDF, Kindle, ePub) for just $24.95:

  • Treading on Python Volume 1: Foundations
  • Treading on Python Volume 2: Intermediate
  • Two Scoops of Django ...
Read more ...

Python Yields are Fun!

Friday, November 22, 2013 (permalink)

While you can optimize the heck out of your Python code with generators and generator expressions I'm more interested in goofing around and solving classic programming questions with the yield statement.

note: For this article, since it's easier to explain things as they happen, I'll be including ...

Read more ...

Made Up Statistics

Friday, July 26, 2013 (permalink)

Years ago my good friend Miguel Araujo and I presented on Advanced Django Form Usage. Slide 18 of that talk mentioned some made up statistics. Here they are for reference:

  • 91% of Django projects use ModelForms.
  • 80% ModelForms require trivial logic.
  • 20% ModelForms require complex logic.

In Chapter 10 of ...

Read more ...

Annotated History of My Most Used Shell Commands

Wednesday, April 10, 2013 (permalink)

An oldie, but a goodie. This time I annotate it with reasons as to why things are used so much. If you blog, post your own!

For reference, anything after a "#" is an annotation.

$ history | awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn |head ...
Read more ...

Fixing Python's String class

Monday, April 01, 2013 (permalink)

Ever wonder why Python's str or unicode types lack obvious length methods? Yes, we can get the length via the special __len__() method, but instead as Python developers we get the so-called 'luxury' of discovering length via the Python's built-in len() function. So instead of calling the length ...

Read more ...

Beginner's Guide to PyCon 2013 Part III

Sunday, March 10, 2013 (permalink)

This is Part III in a series of blog posts about PyCon US 2013. The goal is to provide a handy reference guide for first time attendees of the world's largest Python conference. Part I was mostly about tutorials, Part II was mostly about the first day of talks ...

Read more ...

PyCon Tutorial: Wiring Up Django Packages

Friday, March 08, 2013 (permalink)

You just finished the Django tutorial. What now?

You learn how to Wire Up Django Packages!

This is a 3+ hour PyCon tutorial on March 14th at 1:20pm, in Santa Clara California at PyCon US.

In alphabetical order, the instructors:

Tutorial Description ...

Read more ...

Beginner's Guide to PyCon 2013 Part II

Wednesday, January 23, 2013 (permalink)

This is Part II in a series of blog posts about PyCon US 2013. The goal is to provide a handy reference guide for first time attendees of the world's largest Python conference. Part I was mostly about tutorials, this post will be about registration and the first day ...

Read more ...

Beginner's Guide to PyCon 2013 Part I

Tuesday, January 22, 2013 (permalink)

New to Python and thinking about going to the upcoming PyCon US for the first time? You know, that big Python conference taking place near San Francisco in March?

Or perhaps you signed up already and are getting worried about being overwhelmed by hundreds of tutorials, talks, and activities?

No ...

Read more ...

New Year's Python Meme 2012

Friday, December 28, 2012 (permalink)

Tarek Ziade has a habit of ending the year with a Python-themed meme. I've matched his meme the times he previousstarted it, and as you can tell from the title of this blog post I'm matching him yet again.

1. What’s the coolest Python application, framework or ...

Read more ...

Los Angeles Open Source Sprint on Nov 4th!

Sunday, October 14, 2012 (permalink)

https://s3.amazonaws.com/pydanny/la_hackathons.jpeg

Yet again, myself, Audrey Roy, and a small but elite cadre of volunteers are feverishly at work putting together another Los Angeles open source event. Our last effort went smashingly well, and like any good engineer, we're ready to scale up - this time to 150 attendees!

LA Open Source ...

Read more ...

We need more PyCon US 2013 submissions!

Thursday, September 27, 2012 (permalink)

The PyCon US 2013 call for papers (CFP) ends tomorrow, September 28th, 2012. We need more talk and tutorial submissions. Talks are 30 or 45 minute efforts in front of the PyCon audience and are recorded for posterity. Tutorials are three hours long and are given to attendees who have ...

Read more ...

Installing Pycairo on Mountain Lion

Tuesday, September 04, 2012 (permalink)

Pycairo is the binding for the cairo graphics library. It's also not something you can get running with a simple pip install py2cairo. After many hours of working the search engines and dancing to the configure/make/make install melody, I figured out an answer that worked for me ...

Read more ...

Thoughts on my stack

Tuesday, September 04, 2012 (permalink)

I'm an open source developer. I use Python, Django, PostgreSQL, JQuery, MongoDB, Memcached, and Redis. I push production code to Linux servers.

And yet:

  • My laptop runs Apple's Mac OS X.
  • My primary editor is Sublime Text.
  • My production servers are provided mostly by Heroku.
  • All my sites ...
Read more ...

Python dictionary as a class

Saturday, September 01, 2012 (permalink)

A long time ago, circa 1999, when I was working in a certain procedural language I found a library that added objects to the language. It did so by playing interesting tricks with key/value structures, which in Python are called dictionaries. In 2005, as a new Python user, I ...

Read more ...

A Public Service Message to the Python Community

Monday, August 20, 2012 (permalink)

Hi, I'm Daniel Greenfeld. You might know me from my blog. I'm here to talk to you about a very import subject: Submitting your talk early to PyCon US.

Last year there were hundreds of talks were submitted for just a very few speaking slots. Unpaid volunteers labored ...

Read more ...

PyCon 2013 Talks/Tutorials I want to see

Monday, August 20, 2012 (permalink)

This morning, Jesse Noller, the chair of PyCon US, suggested a meme, "PyCon 2013 talks/tutorials I'd like to see". Here is my meme submission:

1. Python Obfuscation Contest

This certain-to-be-controversial talk idea would be where the speaker would solicit Pythonistas to submit a single arcane Python code module ...

Read more ...

Python dictionary vs JavaScript object: Dynamic Keys

Sunday, August 19, 2012 (permalink)

One of the things I noticed a long time ago with JavaScript is that when you create objects you can define keys outside of strings:

> var o = {city: "San Francisco"}
  Object

In JavaScript, this is valid. In Python, you'll get a NameError:

>>> o = {city: "San Francisco"}
Traceback (most recent ...
Read more ...

Attaching custom exceptions to functions and classes

Thursday, August 02, 2012 (permalink)

Having too many custom exceptions on a project can be a pain, but a few choices ones are really nice. The problem is that in complex libraries having to import both functions and exceptions becomes a drag. To mitigate having to remember to import custom exceptions, this is a handy ...

Read more ...

July 15th, 2012 LA Open Source Recap

Monday, July 16, 2012 (permalink)

On July 15th, 2012, at the July LA Hackathons Open Source event, over 60 Python, Django, Ruby, Ruby on Rails, PHP, JavaScript, Node.js, Perl, and Clojure developers arrived to work on a variety of projects. We went from 10 AM to 10 PM, and there was much coding and ...

Read more ...

Simple HTTP Basic Auth Wall

Monday, July 09, 2012 (permalink)

I have a client who wanted their entire unlaunched public content site quickly but temporarily blocked for a short period of time. He wanted a universal password so he could send the site to reviewers, done quickly, and nothing else. In a few days the site will launch, and even ...

Read more ...

PyCon Philippines 2012 Day 2

Thursday, July 05, 2012 (permalink)

The second day of PyCon Philippines 2012 had a really good turnout. My unofficial estimate is that we had about 90% of the attendees from the first day attend (with the unfortunate exception of most of the faculty and students of Agoo Computer College).

The day started with...

Lightning Talks ...

Read more ...

PyCon Philippines 2012 Day 1

Tuesday, July 03, 2012 (permalink)

PyCon Philippines 2012 (PyCon PH) happened just this past weekend at the University of the Philippines Diliman (UP Diliman) campus in Quezon City, which is part of Metro Manila.

I can assure you that PyCon PH was an wonderful, amazing, humbling experience. I'm hoping that this post and others ...

Read more ...

Announcing PyCon Philippines!

Saturday, June 09, 2012 (permalink)

PyCon Philippines 2012, set to occur on June 30 and July 1, is the first Python programming conference held in the Philippines. PyCon is a volunteer run effort that brings together Python developers from a variety of backgrounds and skill levels into a friendly, cooperative environment in order to educate ...

Read more ...

May 12th, 2012 LA Open Source Recap

Monday, May 21, 2012 (permalink)

On May 12th, 2012, over 50 Python, C++, Ruby, PHP, JavaScript, and Node.js developers arrived to code on a variety of projects. It was awesome! Tons of open source projects saw contributions, and people across languages and frameworks worked together.

http://farm9.staticflickr.com/8007/7193954598_1b071cb5e4.jpg

Event Background

Less then two weeks before May 12 ...

Read more ...

CSS Hacking to make my code samples legible

Friday, May 11, 2012 (permalink)

I've been very happy with Pelican as a blog engine so far, and haven't even moved off the sample theme. There's just been one problem: Myself and others have had a lot of trouble reading the code snippets.

I didn't have time to cook up a ...

Read more ...

Los Angeles Open Source Sprint on May 12th!

Tuesday, May 01, 2012 (permalink)

http://farm9.staticflickr.com/8022/7132778527_6e3b49b313_o.png

This is a day long coding event in Los Angeles for Open Source developers of all languages and skill levels to come and code like fiends. They'll be joined by dozens of either really smart coders or nice people like me. Sponsors are providing food, drinks, venue, and more ...

Read more ...

Calendar About Nothing

Wednesday, March 28, 2012 (permalink)

On October 16th, 2011, which was one hundred and sixty-four days before I published this post, I resolved to get myself onto the Longest Streak list of Calendar About Nothing. Today, with this blog post, I've managed to do just that - get on the Longest Streaks.

Calendar About Nothing ...

Read more ...

Launching our API at PyCon 2012

Friday, March 09, 2012 (permalink)

A few months ago me and my fiancee, Audrey Roy, launched our start up, Consumer Notebook. It's a Python powered product comparison site that combines the best features of Open Comparison, Yelp, Consumer Reports, and Pinterest. We've worked day and night to make it better, with countless members ...

Read more ...

The sorry state of Python OAuth providers

Monday, March 05, 2012 (permalink)

This is one of those challenging posts to write. The people whose projects I'm going to describe have put in a lot of dedicated, hard work to overcome a challenging subject. Writing an OAuth consumer is a hard problem and writing an OAuth provider is an even harder problem ...

Read more ...

You should Heroku

Tuesday, February 28, 2012 (permalink)

In mid-November me and my fiancee, Audrey Roy began our startup. We had been frustrated with trying to do on-line product research and came up with an idea to take the lessons learned from Django Packages / Open Comparison and apply them to a commercial effort. The result has been Consumer ...

Read more ...

I use this

Saturday, February 25, 2012 (permalink)

I had been meaning to do this for some time, and even had a nascent page for it on this site already. I just noticed my old friend Jessica Hammer was featured on usesthis.com. Then I remembered Kenneth Reitz blogged about his tools not that long ago. Looks like ...

Read more ...

PyCon Australia 2011 Review

Friday, February 24, 2012 (permalink)

In June of 2011 I had the good fortune of having my then girlfriend, Audrey Roy, now fiancee, invited to present a keynote speech at PyCon Australia 2011.

I was terribly excited for her to get that invitation, and that excitement was compounded when they allowed me to present on ...

Read more ...

My PyCon 2012 Schedule

Wednesday, February 22, 2012 (permalink)

Here I was thinking that this year's PyCon wasn't going to be so busy because I didn't submit a talk or tutorial. Ha! What the heck was I thinking?

Here's what I've already got in the works.

Wednesday, March 7th

Me and Audrey are driving ...

Read more ...

Selected for PyCon StartUp Row

Tuesday, February 21, 2012 (permalink)

Me and Audrey have been working hard on Consumer Notebook, a Python/Django based project. We submitted it to PyCon StartUp row and found out this morning we've been accepted. Hooray!

From the PyCon StartUp Row winner's post, here is a little bit of what we're about ...

Read more ...

Parsing MongoDB URI

Monday, February 20, 2012 (permalink)

Rather than hard-code the configuration into a Python based settings file, when using a PaaS such as Heroku you want to pick up the MongoDB URI from the system settings. Here's what I do:

# get the dynamic elements from the MongoURI
import os
import re
r = r'^mongodb\:\/\/(?P ...
Read more ...