My Other Sites


Python Web Development with Django: Review July 3rd, 2009

My roommate bought Python Web Development with Django Developer’s Library by Jeff Forcier, Paul Bissex, and Wesley Chun, and I decided to use that as my guide for learning Django. When I looked at the reviews for the book at Amazon, it seemed promising. I didn’t delve deep into them, only looking at the first few comments. So, immediately I began. Of course, I already had Django installed, and if you had been following my blog you’d know of the crap I’ve had to deal with getting FastCGI to work in Windows 7 (I’ve given up for now, but I’ll get back to it one day). In any case, I open the book, and begin working on the first example in the book, the Blog. It seemed simple enough at first, they would give me code, and I would write it up. When they said to run it, I promptly did so. It was a shame that when I followed the example to the letter that it did not work.

So I attempted to fix any problems I was having with the thing. Turned out I had to delete my database and reinstall it as the authors did not mention that syncdb did not fix your database if you make structural changes to your model (which I did, since I had made a mistake). In any case, after that little hiccup, I managed to get the blog application working. Yay for me! It was fairly painless but it didn’t teach me anything about how to actually use Django. That was what the next three chapters were for.

I quickly began to realize that those three chapters simply cover way to much and assume that you know exact what is going on at all times. Now, I’m not an expert Python developer, nor do I claim to be one, and the book doesn’t assume otherwise, but their examples out of context are fairly hard to follow. They do not even teach you how each of the different methods work, only that it is how the framework works. In any case, I decided to skim that part of the book, as I had a feeling that the next four chapters (more examples) would probably be a great deal more help.

They weren’t. I mean, okay, I did each and every one. They all didn’t work right out of the box. Seriously, I had trouble completing each and every single one of them. I don’t even remember the problems I had with each, but needless to say at least one of the problems was various typos. During one of the later examples I actually downloaded the supplemental source code because I had pretty much given up. The source code also did not work, and I had to fix that too. Honestly, I think the authors were in a bit of a rush to release this book, because how can you publish source code that does not work? You can’t prove a book is grammatically correct and that it is spelling error free, but certainly you can make sure code actually compiles and works as expected, especially with the scope of the examples presented.

To be fair, it is a bit of a pain when the authors assume you’re in a Unix environment. For all you Windows people (esp. Windows 7), you’ll just have to learn to adapt and be resilient. For example, the authors did mention symlinks at some point. I didn’t realize I could do symlinks in Windows, so I created an Alias in my configuration file in Apache instead. Not a big deal, but something to keep in mind. Overall I found the book to be alright as far as decent examples to practice with… AFTER you’ve exhausted your online resources. Honestly, I got much more out of this video than any of the examples in the book, simply because it’s a full 20 minutes of following someone create a simple application in Django. If you can get past the Indian voice and the fact that he’s using GRAPHICAL VIM, then you’ll be alright.

Oh, and I also highly recommend the online Django documentation, it is actually quite nice if you know how to use Google.

Pythonic CGI Up And Running May 3rd, 2009


Please visit my projects page if you want to see my Othello AI program, written purely in Python. I should add that some of my teacher’s code from high school is buried within my modifications so he deserves credit as well, which I’ll fix shortly. For now you can give it a whirl. I’ll be posting a download link with a template for creating your own Othello-playing AI that will work with my program. I still have to work out the security issues of having people upload their own code, so that won’t be available for now. I can also post the non-web source code for download.

Learning about CGI with Python brings me one step closer to delving into Plone and Zope. I could have just gone at it right away, but I don’t have too much time yet as I’m still in school and I needed to brush up on my Python. Now that I’m all set, I can start playing with web frameworks. Should be fun.

Python Code Recovery A Success May 1st, 2009

I’ve recently begun a mini project to get my old high school AI code working once again. We created AI’s to play the game of Othello against each other, and these programs were written in Python. For some stupid reason, I only saved the .pyc files of pretty much all of the AI’s I had except for one, which happened to be not that great (loses to randomness). But I digress.

The point is I got the Othello referee (the program which lets AIs battle each other) to work once again by letting it read from .py files and by cleaning up its display code. I also fixed up the only AI file I had so that I could test the referee once more. It really does bring back memories.

I’ve created a template AI file which contains the code needed for any AI to function, and has comments for which defs were left blank. One of my goals here is that anyone wanting to learn Python and work on something a little more interesting can use the template to create as complicated or as simple an AI as he or she wishes. This of course leads me to my other goal: to integrate this Python script into my website and have people be able to upload their AI’s and battle their creations against those on the system. It’s bold, but I like it a lot. I really do want this as I feel it would be something cool that people could do to make learning Python fun. It’ll also allow me to play with programming web with Python, working with a GUI framework for Python (I’m gonna look into wxPython), and will let me test the Python capabilities of my host (Dreamhost is awesome).

I’ll keep logging my Python successes and failures as I progress through this little project of mine. Wish me luck.

Python Backwards Compatibility Sucks April 29th, 2009

A few days ago I found all of my old Python code from high school. I have various files from small assignments, but the one program I am truly interested in resurrecting is the Othello AI program. I have the Othello referree which allows different AI’s to play against one another, and I also have a bunch of compiled Python files for the different AI’s I happen to have. There’s a bit of a problem however: when I try to use the referee to upload these AI’s, I get a bad magic number error.

What!? Bad magic number? And I thought Ruby was full of magic, turns out Python has a whole error around bad magic numbers. I went to look up this error, and I found out that Python doesn’t do well with importing compiled python code (pyc) if it was compiled using an older version of Python. This means all I have to do is recompile the source code with the version of Python I have now. Unfortunately, I don’t have the source code…

Well then I thought, how about I just grab the version of Python that I used to compile them. That’s turning out to be difficult. I grabbed the oldest version of Python that I probably could have used from the Python site, but now none of the AI’s show up in the othello referee list. I have no idea why this is the case, and I’m running out of options.

I have one source for one AI. I’ll have to use this code as a template for other AI’s to be made so that I can have a working version of this program once again. Either that, or I need to find a decompiler or someone who knows how to get old pyc’s to work with newer versions of Python. If anyone knows, drop me a line.

New Header, Calendar And Yay For Python! April 26th, 2009

Yay I found an okay header.

But also, RSS works, and I know have a Google calendar up which I hope to actually use. I’ve removed the .php extension that shows when you navigate to different sections of the site, which is nice (being able to create your own .htaccess is awesome, don’t get a host that wont let you!).

I’ve also found my old Python programs! There was a cool project we did in AI where we got into teams of two and create AIs that played Othello. The best part about this was that each of us would create our own, and then our teacher had a master program which loaded two AI’s and had them play against each other. The game was graphical so it was a lot of fun watching our AI’s duke it out. I really hope I have all the code to be able to do this because it is pretty cool. Who knows, if I get it working I could hold a little Python AI programming contest to help others learn Python (it’s a cool language, and AI programming is also awesome).

I’m still at a loss for what to do with the right sidebar, however I don’t want to remove it. This means something absolutely has to go there, but I’ll figure that out later. Oh, and my college programming projects are also still missing from the projects page. I’ll be putting those up a little at a time throughout the week.