[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

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

Mark Lawrence

3/17/2010 8:57:00 AM

Shashwat Anand wrote:
> 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
> noun
> 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
> ?
>
>

Are you thinking of this?
http://pypi.python.org/pypi/pyobjc-framework-DictionarySe...

HTH.

Mark Lawrence