code.py

A blog about life, the universe, and Python.

A bit of Mathematica

Posted by thepythonista on 29 September 2008

Today’s post was motivated by a problem at Project Euler involving the Collatz conjecture. Since this is a little bit spoiler-y, I’ve included the main body of the post after the cut. Don’t read it unless you’ve either solved the problem at Project Euler or you’re actually looking for spoilers. You have been warned.

Read the rest of this entry »

Posted in code | Leave a Comment »

Licensing

Posted by thepythonista on 8 July 2008

It occurred to me just now that, although I’ve put some code out there on this blog, I haven’t attached a license to it. Well, now I have. See my about page for details.

Posted in free software | Leave a Comment »

Pure Python Fibonacci Numbers

Posted by thepythonista on 3 July 2008

A while back, I came across this post, in which the author implements a couple of different algorithms to generate Fibonacci numbers in Python. What he finally ends up with is an algorithm that essentially does matrix exponentiation by repeated squaring, and it runs fairly fast.
Read the rest of this entry »

Posted in code, python | Leave a Comment »

Seek and ye shall find….

Posted by thepythonista on 13 June 2008

One of the things I like best about the Python community is that, chances are, if you’re after a module to do X, someone’s probably already written it (and likely at least 2 or 3 someones have).  While the Python Package Index (PyPI) isn’t nearly as comprehensive as Perl’s CPAN, or the LaTeX equivalent (CTAN), there’s a lot of good stuff on there.

Specifically, I was looking for a database interface implemented as a Python iterator. Why, you might ask? Well, so I could do stuff like

results = [r for r in records if "foo" in r.name]

using list comprehensions. I know I could easily do this stuff with SQL cursors, but, for this particular app, I’d like to avoid that as much as possible, keeping the code “pure python,” if I can.

A quick search of PyPI yielded buzhug, which does exactly what I want it to. I can’t really evaluate it yet, since I’m not done playing with it, but I’ll probably post about it sometime later. If anyone else has any experiences with buzhug, I’d really appreciate if you dropped me a comment.

Posted in code, free software, python | Leave a Comment »

Don Knuth is my homeboy

Posted by thepythonista on 3 June 2008

Soon, I’ll even have the t-shirt to prove it. :)

Posted in uncategorized | Leave a Comment »

The quest to translate PyPy

Posted by thepythonista on 3 June 2008

I’ve been playing around a little with PyPy, the reimplementation of Python in Python, recently.  Unfortunately, my laptop isn’t beefy enough to translate the Python-based interpreter to C.  I guess it’ll have to wait until after I get another gig or two of RAM (it reportedly takes about a gig just to compile the interpreter to C code which gcc can then compile, to get a native Python interpreter).

You may have foiled me this time, PyPy, but I’ll be back!

Posted in code, free software, python | Leave a Comment »

Which Python GUI toolkit is right for you?

Posted by thepythonista on 2 June 2008

I just came across this site and thought it was neat.  Rank each criterion with a number from 1-100 and the site will tell you which of Python’s GUI toolkits best suits you.  According to it, I should use wxPython, but I’ve always liked Tkinter best myself. :-)  Now that Tkinter uses native widgets on all platforms, it’s an even better choice than before.

Posted in python | Leave a Comment »

It’s official: I’m a switcher.

Posted by thepythonista on 2 June 2008

I’ve decided to switch web browsers.  I’ve been using Firefox, and, while it’s been generally adequate, I’ve found Opera to be superior.  Opera seems to use less memory, have more features, and be faster than Firefox, based on my testing.  On the other hand, Opera is not Free Software.

I’m rather disappointed about this last bit.  If Opera were Free Software, chances are I wouldn’t even bother making a post about it.  Ideologically, however, it feels like a defeat.

If anybody knows of any web browser that

  • Runs on Linux (preferably installable from the Ubuntu repositories),
  • Uses significantly less memory than Firefox,
  • Renders relatively quickly and with an eye toward standards-compliance, and
  • Has support for Flash and Java

I’d like to hear about it.  In the meantime, I’m going to keep testing other browsers, but I suspect I’ll end up sticking with Opera.

One thing Opera has on top of all those other things is a wiki with lots of tips and tricks for running it.  That’s a small plus, but I’d take a browser without a wiki that was Free Software and met my other conditions over it any day.

Ho hum, what’s a Pythonista to do?

Posted in free software | 1 Comment »

I’ve been Reddit-ed!

Posted by thepythonista on 2 June 2008

Well, 500+ hits in one day, less than a week after starting this blog.  Who’da thunk it?

Posted in uncategorized | Leave a Comment »

Help a Pythonista out!

Posted by thepythonista on 2 June 2008

Has anybody read Programming Collective Intelligence?  I’m considering purchasing it from amazon.com, but I don’t really trust the reviews there much.  Post a comment if you’ve read this book, and tell me what you think of it!

Posted in code, python | Leave a Comment »