Python Posts

166 posts tagged with python

The last two weekends I scratched a web development itch. I've been using KeepNote to store notes for years now. It's a nice simple desktop app, which I use to store details such as past addresses, account numbers, phone numbers etc. And more sensitive information like PIN numbers and passwords.

I configured KeepNote to store notes in Dropbox so that I don't risk losing anything. This has worked quite well, but I've always been frustrated that (a) I can't access my notes on my mobiles devices, and (b) I'm relying on a third party to keep my secrets. continue reading…

I never intended to write a template system for Moya. Originally, I was going to offer a plugin system to use any template format you wish, with Jinja as the default. Jinja was certainly up to the task; it is blindingly fast, with a comfortable Django-like syntax. But it was never going to work exactly how I wanted it to, and since I don't have to be pragmatic on my hobby projects, I decided to re-invent the wheel. Because otherwise, how do we get better wheels? continue reading…

The feed for this Blog has been broken for a while. I knew it was down; somebody was kind enough to alert me on twitter. I've been procrastinating fixing it because a) the Django code I wrote to power this blog is old and crusty, and b) I've been busy with another project. I only got around to fixing it now, because I have something to announce. Stay tuned.

Can't believe the last time I posted a blog was 2013. Where does time go.

My client is looking to hire a new Python developer, initially for an 8 month contract. It's a home working position, we communicate mostly via Skype / email / gtalk etc. Although we do meet up in meatspace from time to time, so ideally a candidate would be in the London / Oxford area.

You will be working with your truly. The projects I've been working on are in the server side of web-enabled devices. The web interface is written in Django, so you'll need the usual battery of front-end technologies; HTML, CSS, Javascript etc. We have a Twistd server which communicates with devices in the field, that my client produces. In the middle we have dynamic user interface generation from XML. continue reading…

Here's a Python gotcha that I spent some time tracking down. I'm writing it up in the spirit of saving developers a debugging headache in the future.

I had an integer with a single bit set, and I wanted to find the index of that bit. For example, 4 in binary is 00000100. The 1 is at the third position from the right, which should give an index of 2 – since the first position is 0.

You can do this in two ways; either check each bit in turn until you find a 1, or you can use math as a shortcut. I chose the math solution:

Simple right? Finally staying awake in high school maths paid off. So simple that it was the last bit of code I suspected to be broken (spoiler: it was). continue reading…

Instant Pygame for Python Game Development How-to

Packt Publishing have released Instant Pygame for Python Game Development How-to, a guide to getting started with PyGame, written by Ivan Idris. This title will help you get over the initial hurdles in setting up a PyGame environment and developing your own games.

I was the technical reviewer for this book.

When I'm debugging Python I tend to sprinkle my code liberally with print statements. Trouble is, I forget which files I added those print statements to and have to waste a few minutes tracking them down. Time which could be better spent doing pretty much anything else.

Not sure why I didn't think of this before, but I hacked together something that automatically prints the file and line of the print statement next to the output.

Here's the code:

To use it, save it as ‘debugprint.py’ then imported it somewhere. That's all you need to do. Works on Python 2.7 and probably other 2.X Pythons.

Here's what happens if you do it from the console:

For print statements in your app, you will get something like:

Ben Timby has committed code to PyFilesystem that lets you expose any filesystem over FTP. We've had the ability to serve filesystems over SFTP (secure ftp) and XMLRPC for a while, but plain old FTP was a glaring omission–until now.

You can serve the current directory programatically with something like the following:

The same functionality is also available to the fsserve command. The following is equivalent to the above code, but from the command line:

You'll probably need root privileges (i.e. sudo) on Linux for these examples.

With the server running, you can browse the files on your home directory with an ftp client, or by typing “ftp://127.0.0.1” in to your browser. Any of the other supported filesystems can be served in the same way. continue reading…

I made currency site available for testing today. See my previous post for the back-story, but in essence currency site is a virtual currency platform.

I sometimes object to the word virtual in ‘virtual currency’. Most of the money I possess is not in any physical form; it's merely a number stored in a database somewhere – and transactions occur without any kind of physical objects changing hands. So the word ‘virtual’ seems entirely redundant, since there's is no qualitative difference between virtual and ‘real’ money I can see. The only difference is the level of trust in the system. continue reading…

A while back a friend told me about something called community currency, also know as Local Exchange Trading System. The basic idea of which is that people within a geographical area can exchange goods and services with bespoke unit of exchange rather that traditional cash. So, for instance, you could mow a few lawns in exchange for guitar lessons – even if it isn't the guitar teacher's lawn you are mowing. There's no physical currency as such, members of the community currency rely on volunteers to keep track of how much currency they own. I think this is a marvellous idea. It promotes healthy exchanges without the need to muddy things with something as vulgar as cash. But what struck me after a bit of research is how the whole system is in dire need of mechanisation! There's no centralised place to view your ‘account’ or way to do transactions online, and I figured there should be. So that has been my hobby project for the last few months, I've been building such a site which has recently come together to a point where I'd like to gauge how much interest is out there. I haven't even come up with a name yet, so I've been calling it by the rather uninspired moniker of ‘Currency Site’. continue reading…