infundibulum

This one thing

January 30th, 2005

I have this one idea.

I tried to make it go away, but I’ve been having it for a long time now. It’s like, when you tell yourself that something isn’t going to work, but some inner voice keeps echoing back and saying, “Okay then. So anyway, about that idea we’re not supposed to be thinking about…”

And that happens to you all the time, every day. Eventually, you figure you should just listen to it.

I’m not going to tell you what this idea is. But here’s the way I think about it:

It’s like going into a gym, and blowing up a big, big, balloon, and then letting it go. And watching it fly around, all crazy, just to see what will happen.

Getting crazy with gettext()

January 29th, 2005

serendipity » Locali(s|z)ation and internationali(s|z)ation

A fascinating post on the perils of gettext().

I have lots of thoughts on this kind of stuff, but I promised myself I’d sleep before sunup.

O_o

P.S. Dear self: Happy 30th Birthdayy.

And don’t worry, 30 is the new 60.

Liberty in their Lifetime?

January 28th, 2005

I’ve followed the Free State Project in the news for a while with a mix of fascination and dread. If you’ve not heard of it (which wouldn’t be terribly surprising lately, given that media attention has been waning), FSP consists of a bunch of Libertarians who decided to get together and move to New Hampshire. And, uh, take it over.

Then, their reasoning went, they turn the place into a Libertarian’s paradise — no taxes, no gun laws, pass the ganja, you know, that sort of thing.

There have already been some conflicts with locals who do not fail to detect the iffiness of it all. Now another divisive topic is on the agenda, and suprise, surprise, the Free State crowd is mixed up in it:

House debates hate crimes repeal

It’s actually a Republican bill, and here’s the elevator pitch:

Alton Republican Sen. Robert Boyce said there’s no way of knowing for sure what’s really in the mind of a criminal offender, and this law gives the impression the government is all-knowing.

“If you want to increase the penalties of the crimes across the board, that’s fine, but don’t base it on the thoughts of the perpetrator,’’ he said.

In other words, they say, don’t make the punishment worse simply because the crime was motivated by race or sexuality or any of those ever so vague concepts. Uh, right.

There shall be no such vagueness in the Free State! Sweep away all such bureaucratic pansy ass nonsense!

“The First Amendment guarantees the right to speech and common sense tells me thought is an extension of speech,” said Dave Mincion of Dover, who was representing a group called the Seacoast Porcupines. Mincion, who moved to New Hampshire last year, said the group is comprised of members interested in the Libertarian “Free State Project,” but not affiliated with the group.

“Crime should be punished, but like it or not we have not developed the technology to know what people think,” Mincion added.

Gotta hand it to FSP, standing up for your First Amendment Right to think whatever you want about the person you’re kicking the shit out of.

Oh, whoops, it’s not really the FSP. It’s a splinter cell group of the Free State Project. Just like the Freetowners… or… er… what where they called again?

Look guys, maybe you should have started with Rhode Island? Because you’re not getting anywhere with publicity like this.

Fortunately.

SmellML

January 25th, 2005

Smart Mobs: Transmitting fragrance by SMS

The researchers said they quickly realised that smells could be propagated over networks and the Web. And so they have created XML Smell, which they claim can define in universal and standardised way the transmission of smell which allows the transmission of fragrances by email, by SMS to a mobile phone, or via a TV show.

I call for caution. The first people who start transmitting this stuff are going to be very large, sweaty sysadmins.

Maps.

January 22nd, 2005

Do you ever feel like maps are creepy?

I was just talking to a friend of mine in Brazil, and he was looking for US maps. So I was Googling around.

And I suddenly had the weirdest feeling, looking at these sprawling networks of highways. It’s a cliché to make the analogy between veins and arteries and highways (ever since Koyaanisqatsi, I guess), but the thought is unavoidable.

It’s interesting, but it creeps me out, too.

streets and veins...

Snow shock

January 22nd, 2005

You get up and your head is filled up with all the things that you’re going to do today.

Then you glimpse it out of the corner of your eye through the window: it’s snowing.

Python as a Multilingual Command Line

January 14th, 2005

Here’s a bit on what’s holding up progress on Fieldmethods, and some thoughts about Python and Unicode.

Consider what’s probably the simplest multilingual application imaginable: open some text from a file and print it out again. As an example, I used some text in Georgian, which I snagged from this Unicode.org page. (A good place for finding random samples of Unicode text in different languages.)


>>> import os,sys
>>> sys.getdefaultencoding()
'ascii'
>>> # Let's open up our utf-8 encoded Georgian text:
>>> georgian = open('georgian.txt').read()
>>> # Now we convert the text to Unicode:
>>> georgian = unicode(georgian)

Traceback (most recent call last):
File " “, line 1, in - toplevel -
georgian = unicode(georgian)
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xef in position 0: ordinal not in range(128)
>>> # Oops! Kartvelian chaos!

Do you want to get into character encoding and code pages and codecs and…? Well, maybe you do. I think it’s kind of interesting, myself, in the way that, uh, Rubik’s Cubes are interesting.

But my readers at Fieldmethods won’t. They’ll turn around and say “Sorry, too techie, I don’t have time for this.”

So I just want to tell them how to avoid thinking about encodings as much as possible. That means making utf-8 the default, and here’s what has to happen.

They need to take a few steps to set up a multilingual prompt.

Here’s what it looks like when everything is working:

a multilingual prompt

Great! See that Georgian text in there? If you have the fonts, and you have Python configured correctly, we get to deal directly with the text. You see text, not escape codes everywhere. (Although you can see that in certain circumstances, as in that sixth line, you still see escape codes. I’m not sure why that is, but we’ll have to be happy with visible text after print statements.) Note also that we’re not going to be inputting random stuff from the keyboard, we’re just going to read files, but we still want to be able to see it.

So here are the three platforms I’m targetting:

  1. Linux
  2. Windows XP
  3. OSX

Now, one of Python’s strong points is that it’s pretty consistent across these platforms (the IDLE editor, in particular, is almost identical across all three). And the Unicode support is there.

Unfortunately, the default configuration for a new install of Python, on any platform, is not set up to encourage use of Unicode in this way. Namely, the default encoding is not utf-8 but ASCII. Whyascii? Inertia, I guess, but I really have no idea. Arguments about default encodings, codecs, conversions, etc, etc, go on endlessly in Python newsgroups. But pretty much everyone agrees that you can’t cover too many languages with ASCII. Not really even English, if you ask me.

Mostly such arguments are based on the idea that everything has to be portable between systems. But that’s not my prime consideration. My prime consideration is that programs be portable between human languages. We’re going to be “doing science” on language, and it only makes sense if we can apply it to any language. If I write a function count_letters(), I want it to work with English, French, Georgian, Persian, Cakchiquel, WHATEVER.

With that goal in mind, having the default encoding set to utf-8 is the way to go.

And that’s what I might need your help with:

How do I make it as painless as possible for users to set that as the default under all three systems?

I learned from Mark Pilgrim’s book how to change Python’s default encoding. What has to happen is that a file named sitecustomize.py has to be put in the Python library. The trickiness comes in with the fact that my readers won’t necessarily be as savvy about things like file permissions as Mark’s are.

The file needs to contain just two lines:


import sys
sys.setdefaultencoding('ascii')

That’s it!

So I plan to make a “Preliminaries” page on Fieldmethods that goes step-by-step through what you need to do to create that file, and where and how to put it where it needs to be on each platform. (And change it back, for whatever reason.)

Because of some nuttiness when Python starts up, you can’t just stick sitecustomize.py in your current directory, or some other directory that’s in your Python path.

Linux isn’t much of a problem: become root, and create the file in

/usr/lib/Python32/site-packages/

Or whereever your Linux distro puts your site-packages directory.

I’m not much of a Windows guy, but it’s my impression that under XP all you have to do is save sitecustomize.py in C:\Python23\ or C:\Python23\site-packages\. I don’t think Windows has any concept of “root” to speak of, so it seems that it’s just a matter of opening the file file in one of those directories and saving it.

Now, OSX, I’m not so sure about: how do you log in as root? How do you write to that directory? If anyone can help me out I’d appreciate it.


Update:

I’ve gotten some help on the OSX front. It looks like there is a distinction between “admin” users and non-admin users, and the “admin” users pretty much have root. Most people who have their own Macs will probably be admin users, so I’ll make that assumption. (Basically you either use sudo or you drag the file with the file system, and get prompted for a password. Not too complex.) Off to write up these three sets of steps.

(Thanks for the help, anonymous Mac guy.)

python unicode

Hi.

January 12th, 2005

Hi there. Check out About me for the big picture.