Created
November 25, 2013 04:27
-
-
Save Fykec/7636366 to your computer and use it in GitHub Desktop.
一个小字典脚本,利用了mac程序本身的字典库
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from DictionaryServices import * | |
def main(): | |
try: | |
searchword = sys.argv[1].decode('utf-8') | |
except IndexError: | |
errmsg = 'You did not enter any terms to look up in the Dictionary.' | |
print errmsg | |
sys.exit() | |
wordrange = (0, len(searchword)) | |
dictresult = DCSCopyTextDefinition(None, searchword, wordrange) | |
if not dictresult: | |
errmsg = "'%s' not found in Dictionary." % (searchword) | |
print errmsg.encode('utf-8') | |
else: | |
print dictresult.encode('utf-8') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment