Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

February 4, 2010

The Joys of Linux

I'm taking a course on Python this semester. I'm really excited about it; there really is no other word for it. I'm sure that my excitement over something as simple as, say, simultaneous assignment, won't be easily conveyed to non-programmers or even anyone besides myself. Nevertheless, the new toys in Python, and particularly the new paradigms (I have never dabbled in functional programming before now, but the potentials offered by yield and generators are making me positively giddy), are very exciting.
The course is just now migrating to Python 3, so in a sense it's good that I didn't get started with the language until now. Unfortunately the default Python documentation (http://docs.python.org/) is for 2.6.4, so it's very easy to get tripped up by outdated information. In a yet more sinister turn, Ubuntu itself uses 2.6 by default! I didn't think this was much of a problem at first. A bit of Googling eventually schooled me in the proper use of update-alternatives, and soon I had set the default python command to call python3. But then the problems came.
The first sign I had that something was wrong was a big red "do not enter"-style notification at the top right, telling me that the update manager wasn't working. I won't go into the details, but I tried all I could to fix it, and somehow I fooled around with dpkg to the extent that GRUB now displayed my install as "Debian". I had all but given up, and I was on the verge of reinstalling, when I booted up today and realized that Dropbox wasn't running, either. Running dropbox in a terminal gave me some strange error, which seemed to hint that the contents of the file were text, not the binary executable itself. So, on a hunch, I opened up /usr/bin/dropbox in a text editor, and what do I see?
#!/usr/bin/python
The dropbox script was formatted for Python 2.x (it was Unicode strings causing this particular error), and my messing around with the default python command was what caused my problems. Evidently the update manager also relied on Python, because resetting the default command back to 2.6 allowed the update manager to run again, and at the moment it looks like everything's going to be okay.

UPDATE: Everything was not okay.

June 22, 2009

Well hot damn!

You know that shell interface to C++ I was talking about? Turns out it already exists! It's a tool called SWIG, used for wrapping up one type of code to be used by another language. And it turns out to be exactly what I'm looking for--a (relatively) simple way to access class member functions directly, in an ad-hoc way.
I don't have the servos with me right now, so I can't test it out fully, but after sweating over a hot command line for the better part of an hour, I've got it to the point of compiling and throwing the expected exception when it can't find the serial port. I am super excited about this, and I'm definitely going to be learning more Python from here on out. And maybe I'll finally get back into Lisp, if I can find a single goddamn interpreter...


EDIT: It works like a charm. :D

June 21, 2009

All you need is cash

Wouldn't it be awesome to have an interactive C++ shell? It's probably best to pay me no mind, because I'm pretty new to the concepts, and I'm speaking from enthusiasm rather than experience... but lately I've been doing a lot of testing of the DynamixelNetwork library using a rudimentary C++ program that's nothing but a few 'cin's, a switch statement, and some function calls. I have to recompile it every time I want to test something new, which makes it very difficult to test a variety of things at once. I'd love to just cut out the middleman, and type the function calls directly at the command line. In this project that wouldn't be much of a problem, although I can see how trying to build a general-purpose shell to handle every function of C++ could pose some difficulties. But it would be a neat utility, if only just for simple testing, wouldn't it?
I've been getting interested in learning Python lately, and today took the first step and found out that Python does indeed have an interactive environment available. And according to Wikipedia, it interfaces well with C++ code (among others). I'm not quite sure how to do it yet... but I think I might try to hack something together. Wait... isn't "hack" more commonly paired with "apart"...?