Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:17:03+00:00 2026-06-03T00:17:03+00:00

I modified the following script to my needs (original found at Fully parsable dictionary/thesaurus

  • 0

I modified the following script to my needs (original found at Fully parsable dictionary/thesaurus and written by samplebias [at samplebias, very useful, thank you :)]):

import textwrap
from nltk.corpus import wordnet as wn

POS = {
    'v': 'verb', 'a': 'adjective', 's': 'satellite adjective', 
    'n': 'noun', 'r': 'adverb'}

def info(word, pos=None):
    for i, syn in enumerate(wn.synsets(word, pos)):
        syns = [n.replace('_', ' ') for n in syn.lemma_names]
        ants = [a for m in syn.lemmas for a in m.antonyms()]
        ind = ' '*12
        defn= textwrap.wrap(syn.definition, 64)
        print 'sense %d (%s)' % (i + 1, POS[syn.pos])
        n1=str('definition: ' + ('\n' + ind).join(defn))
        n2=str('  synonyms:', ', '.join(syns))
        if ants:
            n3=str('  antonyms:', ', '.join(a.name for a in ants))
        if syn.examples:
            n4=str('  examples: ' + ('\n' + ind).join(syn.examples))
        try:
            resp = ("From dictionary:\n%s\n%s\n%s\n%s") %(n1, n2, n3, n4)
        except:
            try:
                resp = ("From dictionary:\n%s\n%s\n%s") %(n1, n2, n3)
            except:
                try:
                    resp = ("From dictionary:\n%s\n%s") %(n1, n2)
                except:
                    resp = ("Data not available...")
        print
        return resp

However, I can tell that I have not modified it very well as it is just wrapped in try/except blocks. But I can’t for the life of me think of a better way to do it (still learning python in an abstract manner). I need it formatted into a variable containing \n as a separator for each line as it is written to a file. Any ideas how I can do this better, and without the lists thing that seems to be happening?

–Define Sunrise

From dictionary:

definition: the first light of day

(‘ synonyms:’, ‘dawn, dawning, morning, aurora, first light, daybreak, break of day, break of the day, dayspring, sunrise, sunup, cockcrow’)

(‘ antonyms:’, ‘sunset’)

examples: we got up before dawn
they talked until morning


thanks! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:17:06+00:00Added an answer on June 3, 2026 at 12:17 am

    Instead of creating a string for each line, just append your text to the output variable from the start.

    resp = 'From dictionary:\ndefinition: ' + ('\n' + ind).join(defn) +'\n'
    resp += '  synonyms:' + ', '.join(syns) +'\n'
    if ants:
        resp += '  antonyms:' + ', '.join(a.name for a in ants)) +'\n'
    if syn.examples:
        resp += '  examples: ' + ('\n' + ind).join(syn.examples)) +'\n'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script (modified to remove any private information). -- This line
How can the following code be modified to run my insert statements 100 at
I've modified my .htaccess file to have the following statement RewriteCond $1 !^index.php$ RewriteRule
I have this timer function, it gives me following exception. Collection was modified; enumeration
I am using the following javascript for form validation: <script type=text/javascript> function validate_form (
I have been using the following preload script to load all the images and
I Use the following VB script( Shell object ) to copy folders & files
I'm trying to do the following with a modified version of the echo server
I am having some trouble with the following script. It should make 3 copies
I have followed the following link and implemented the example for my own script.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.