using DictionaryServices module to get work with python2.6 #OSXspecific

Shashwat Anand anand.shashwat at
Wed Mar 17 09:46:00 CET 2010

I wanted to use dictionary in my OSX terminal.
So I wrote a function dict() in my ~/.bash_profile

dict () {
    python2.5 -c 'import sys, DictionaryServices; word = "
".join(sys.argv[1:]); print DictionaryServices.DCSCopyTextDefinition(None,
word, (0, len(word)))' $@

here is the output:

Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ dict lone wolf
a person who prefers to act or be alone.

The question is why not :
DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word))) works
with python2.6 ?
Is DictionaryService module not available for python2.6 ?

Here is the stack-trace:

Shashwat-Anands-MacBook-Pro:Desktop l0nwlf$ python
Python 2.6.1 (r261:67515, Jul  7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import DictionaryServices
>>> word = "lone wolf"
>>> DictionaryServices.DCSCopyTextDefinition(None, word, (0, len(word)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: NSRangeException - *** -[OC_PythonString
_createSubstringWithRange:]: Range or index out of bounds

Ofcourse it doesnt work with python2.7 too. Is this OSX specific issue ? Can
I make it work with my compiled version of python ? Is there any workaround
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list