Partially Attended

an irregularly updated blog by Ian Mulvany

blog posts about python

Hunting for structure in nested JSON with python just got a whole lot easier

A very common python task that I find myself stumbling over repeatedly is trying to get the syntax right to address or retrieve a specific value to a key in a dented JSON document, in particular if that key is some way down the tree. I’ve just found the library https://github.com/mahmoud/glom which is written up really nicely here: https://sedimental.org/glom_restructured_data.html Before looking at this modele in detail I had thought that I could pass a reference to a key to glom without specifying its location fully in the structure of the input file, but after looking at this for a moment it became clear that this is not what it does, but rather is good at helping to remap nested data structures into new structures, and accessing the data you want via path like queries. ... (more)

python - running commands from within a directory

A neat python snippet for jumping into a directory, running a script, and jumping out again, found on Stackoverflow, provided by Brian Hunt. from subprocess import Popen, PIPE import os import sys class cd: """Context manager for changing the current working directory see https://stackoverflow.com/questions/431684/how-do-i-cd-in-python """ def __init__(self, newPath): self.newPath = os.path.expanduser(newPath) def __enter__(self): self.savedPath = os.getcwd() os.chdir(self.newPath) def __exit__(self, etype, value, traceback): os.chdir(self.savedPath) with cd("~/blog/partiallyattended"): title = new_post.title process = subprocess. ... (more)

Moving from Jekyll to Hugo - urls

I’ve been changing the static blog generator that I use and am slowly moving from Jekyll to Hugo. My main reason is the better support for tags and categories that Hugo supports, but I’m not finding the templating as intuitive in Hugo as in Jekyll, so it’s not a slam-dunk. There are a couple of small differences between the two systems that are making me reconfigure my blogging workflow a bit. ... (more)

Some pittfalls in using iPython to generate talk slides

Yesterday I gave a talk using iPython notebook to generate the talk slides. You can get the notebook on github, and you can see a live version of the slides. It succeeded in generating an artefact that was somewhat literate, in that the code and documentation are nicely woven together, so anyone who has the time can get to exactly the same point that I got to, with this repo, however there were also a couple of problems that I ran into that make me feel that this is not yet ready for mainstream use, specifically: ... (more)

Communicating better, moving from virtualenv to vagrant/Chef

I’ve been using virtualenv for a while, but in the past few months, since taking up the role of head of technology for eLife, I’ve been giving much more thought about how to build scalable development environments. Ever since I was managing connotea, one of the biggest pains has been configuration management. I seem to have spent almost more time on configuring environments than on actually doing any development work (disclaimer, I don’t actually do much coding, I usually do more product management, but it’s really useful to know the development pain points). ... (more)

Super quick start guide to fluidinfo

This is a quick and dirty guide to getting started with fish, the command line tool for fulidinfo. I did it by setting up a virtualenv, as I find it a lot easier to manage python dependancies that way. Setup a virtualenv: % mkvirtual env fi Open the virtual env session: % workon fi Install httplib2: % pip install httplib2 Install readline: % pip install readline Get fish, you can either get it from github and install from source, last time I checked that was: ... (more)

Converting between dates and unix time in Python

Going from a date to a unix time: >>> from datetime import date >>> from time import mktime >>> start = date(2011, 9, 26) >>> mktime(start.timetuple()) 1316991600.0 Going from a unix time to a date: >>> from time import strftime >>> from datetime import datetime >>> datetime.fromtimestamp(int("1284101485")).strftime('%Y-%m-%d%H:%M:%S') '2010-09-10 07:51:25' ... (more)

Django models vs. Pickling objects for object persistence.

I do a bit of code hacking and I often find myself putting objects into pickle files, and reading and writing them in order to fake object persistence. It's easy, but messy and it begins to leave lot's of pickle files sitting around in your path. I've decided to finally make the switch towards using a more grown up persistent object solution. I've decided to try out Django + SQLite. ... (more)

and while we are at it here are the references from that article

References - "Python Objects", Fredrik Lundh, http://www.effbot.org/zone/python-objects.htm - "How to think like a Pythonista", Mark Hammond, http://python.net/crew/mwh/hacks/objectthink.html - "Python main() functions", Guido van Rossum, http://www.artima.com/weblogs/viewpost.jsp?thread=4829 - "Python Idioms and Efficiency", http://jaynes.colorado.edu/PythonIdioms.html - "Python track: python idioms", http://www.cs.caltech.edu/courses/cs11/material/python/misc/python_idioms.html - "Be Pythonic", Shalabh Chaturvedi, http://shalabh.infogami.com/Be_Pythonic2 - "Python Is Not Java", Phillip J. Eby, http://dirtsimple.org/2004/12/python-is-not-java.html - "What is Pythonic?", Martijn Faassen, http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0 - "Sorting Mini-HOWTO", Andrew Dalke, http://wiki.python.org/moin/HowTo/Sorting - "Python Idioms", http://www. ... (more)

BarCamp Cambridge - James talking about HTML5

James is just an interested bysander on the HTML 5 mailing list, hey, it's abarcamp html5 is th enew verison of html applemozillaoperaanyone who joins the mailing list and w3c (which means MS, which means this is going to work in IE) if you have ideas, then you can joing hte mailing list and put ideasforwards for the specification why should we? lots of information is locked up in HTML, not XML, not SVGL ... (more)

BarCamp Cambridge, Tom Morris, Semantic Web for hackers

what's cool about microformats web? is it the stickers?the t-shirtsthe community process urlb.at/2f personal information disastertravel airlines don't talk to railroads microformats say, what problem does it solve? perhaps there is no problem at all what problem does blogging solve?Twitter for christ's sake? no one knows what they do until they are popular e.g. yahoo pipes is not practical yetit is a user experience nightmareand it doesn't have a clear defined purpose ... (more)

Installing Python Image Library on a Mac

I spent about half an hour trying to install the excellent Python ImageLibrary on my mac. It's one of those things that is more annying than itshould be. You get libjpeg from herehttp://www.ijg.org/files/jpegsrc.v6b.tar.gz follow the instructions here onhow to patch the makefile and how to install libjpeg:http://www.kyngchaos.com/macosx/install/libjpeg (all this after installingthe developer tools on mac), only to fail and then discover that there is aprebuilt binary package here:http://pythonmac.org/packages/py25-fat/index.html which works perfectly. ... (more)

live blogging from BarCamp Cambridge, Laura James

Laura JamesAlert Me.Com might get too corporate. trying to do the internet of things, internet access to small devicesthey are implimetning today, and will be shipping later this year.comes from R&D, but working in a shipping they are going to ship a home security system, but they are actuallybuilding a platofrmthat can connect anything that does not require full audio and video using a mesh network that connect to a hub using a 'zigby'output can be things like a lamp that has a color dependant state ... (more)