Learning Python the hard way: __init__.py needed for packages (as opposed to modules)

Just ran into this today, and wanted to get it down so I never forget:

Modules are not packages! 🙂

From the docs, a Module is:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__.

And a Package is:

Packages are a way of structuring Python’s module namespace by using “dotted module names”.

When you create a module and you want other scripts to be able to reference it, you need an __init__.py in the directory containing the modules in order for Python to treat a directory as containing a package.

The error manifests as “ImportError: No module named XXXX”.

All I had to do was touch __init__.py and things worked. I’m sure there are other things I’m going to learn today, but that was a silly one that I didn’t expect, and wasn’t mentioned in the Modules documentation, but is mentioned in Packages.

twittering on 2011-02-09

Invited lecture at Oregon State University: PostgreSQL

Oregon State University invited me to give a technical talk yesterday about PostgreSQL and open source community. It was aimed at graduate level students, and an attempt to recruit them.

It’s not in the slides, but I told a short story in the ‘but there’s a disconnect’ slide. I wanted to convey to them that both the free and open source community and the educational system are failing them when it comes to open source. I attended a conference last fall that had nearly 1000 undergraduate and graduate students. I staffed a booth about open source software, and nearly every student that dropped by couldn’t think of a single open source project they’d ever heard of. With prompting, they’d agree that Linux was probably open source.

We had a discussion about how our community manages conflict, who the big production users of PostgreSQL are, and how folks can get involved. I gave out a few tshirts and buttons, and ran into some old friends from Open Source Bridge.

Event organizers: spaces to have tech events or conferences in Portland

I’ve been asked more than a couple times about places to have events in Portland.

When you google for ‘event spaces portland, or’ you don’t get anything that I’d call useful.

So here’s the list that I’ve compiled:

East Side:

West Side:

Weekly tweet digest for 2011-02-06