dimanche 23 décembre 2007

Controlling Google Earth with Python (API COM)

Google Earth is a powerful and beautiful application. Being able to control the globe, with few lines of Python code, makes you feel like you've got some god-like powers ;)

I've drafted here a short guide to show you how to start controlling Google Earth with Python (through its API COM):
http://docs.google.com/View?docid=dgqhgsgm_933rjw93

samedi 22 décembre 2007

Wrap my head around unicode for Python

Most interesting tutorial I've found: http://boodebr.org/main/python/all-about-python-and-unicode

Keypoints:

  • unicode are "symbols" or "objects" (no fixed computer representation, don't think bytes) and codecs transform them into binary strings (so you can print, store in disk, sent across network...).
  • a unicode string example with some greek characters: unicodeString = u"abc_\u03a0\u03a3\u03a9.txt"
  • you shouldn't 'print' a unicode string without encoding it first (by default Python will encode in ascii which can leads to errors if there are non ascii characters)
  • you can print a unicode "representation": print repr(unicodeString)
  • you encode with the .encode method: binary = unicodeString.encode("utf-8")
  • you can see the binary result like this: print "UTF-8", repr(unicodeString.encode('utf-8'))
  • print "ASCII",unicodeString.encode('ascii','replace') #will replace non-codable characters with '?'
  • from binary to unicode: unicode(utf8_string,'utf-8') # you must specify the encoding if not Python assumes it's ascii
  • once you have a Unicode object, it behaves exactly like a regular string object, so there is no new syntax to learn (other than the \u and \U escapes)
Other links:
* http://www.jorendorff.com/articles/unicode/python.html
* http://evanjones.ca/python-utf8.html
* http://vim.sourceforge.net/tips/tip.php?tip_id=246
* http://farmdev.com/thoughts/23/what-i-thought-i-knew-about-unicode-in-python-amounted-to-nothing/
from my wikinote

dimanche 16 décembre 2007

Iron Python Studio (Python, .Net and the power of Visual Studio for free)

Iron Python Studio is a free IDE for Iron Python (Python for .Net).

You can develop command-line applications, Windows forms and WPF/XAML applications (see the project IronPythonScreenCast (wmv)).

Iron Python Studio has a visual designer for your GUI, code completion, debugger, etc (the usual tools of Visual Studio which makes in particular GUI development so simple).

It can use all the classes of .Net and also use the classic CPython (version 2.4 for now since this first version of the Studio is based on Iron Python 1.1)

More informations on my wiki note