Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Simple dictionary in python using urllib2 and dictionary.com

Dictionary as in the thing that looks up what words mean, not "{}". Anyway Yea, turns out it's really nice and easy to write, also very short. The essential parts are only 5 lines long, but this one catches exceptions if the word isn't real, and also just looks a little nicer:
http://pastebin.com/2r8z3PZM
OR
Spoiler (Click to View)

And condensed to the minimum amount of lines* (for whatever reason)
Spoiler (Click to View)
*It could probably be less, but I'm not perfect and it also gets a lot harder to read

Anyway there you go. Never again will you have to wonder what a word means 👍
Thanks alot, will learn from this! Stoked.
A minor note: you should use urlencode on the word as it could be something like can't (can%27t) or Crème (Cr%C3%A8me)
Great! Learned a lot from this! I might look into remaking this my own way :)
(Jan 6, 2014 07:52 AM)CodeX Wrote:  A minor note: you should use urlencode on the word as it could be something like can't (can%27t) or Crème (Cr%C3%A8me)

You bring up a good point. I can't edit the original post, but here is the fix:

add this line:
Code
word = word[0].upper()+word[1:]
right after word is gotten from input

replace this line:
Code
page = urllib2.urlopen("http://dictionary.reference.com/browse/"+word+"?s=t").read()
with this line:
Code
page = urllib2.urlopen("http://dictionary.reference.com/browse/"+urllib.quote_plus(word)+"?s=t").read()

and replace this line:
Code
import urllib2
with this line:
Code
import urllib2,urllib

🤗🤗🤗🤗🤗🤗 EDIT: 400th post hot dam! 🤗🤗🤗🤗🤗🤗


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[Python] by OracleJul 6, 2019 01:26 AM 2 143 Jul 6, 2019 01:26 AM
Last Post: Oracle
[Python] by CleverUSBDec 29, 2017 11:31 AM 5 315 Dec 29, 2017 11:31 AM
Last Post: CleverUSB