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 6540833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:01:45+00:00 2026-05-25T11:01:45+00:00

I am trying to loop through some 50-odd files in a directory. Each file

  • 0

I am trying to loop through some 50-odd files in a directory. Each file has some text for which i am trying to find the keywords using Yahoo Term Extractor. I am able to extract text from each file, but I am not able to iteratively call the API using the text as input. Only the keywords for the first file is displayed.

Here is my code snippet:
in ‘comments’ list, I have extracted and stored the text from each file.

for c in comments:

    print "building query"
    dataDict = [ ('appid', appid), ('context', c)]
    queryData = urllib.urlencode(dataDict)
    request.add_data(queryData)
    print "fetching result"
    result = OPENER.open(request).read()
    print result
    time.sleep(1)
  • 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-05-25T11:01:46+00:00Added an answer on May 25, 2026 at 11:01 am

    Well I don’t know anything about the Yahoo Term Extractor, but I’d presume that your call request.add_data(queryData) simply tacks on another data set with each iteration of your loop. And then the call to OPENER.open(request).read() would probably only process the results of the first data set. So either your request object can only hold one query, or your OPENER object’s inner workings can only process one query, it’s as simple as that.

    Actually a third reason comes to mind now that I read the documentation provided at your link, and this is probably the true one:

    RATE LIMITS

    The Term Extraction service is limited to 5,000 queries per IP address per day and to noncommercial use. See information on rate limiting.

    So it would make sense that the API would limit your usage to one query at a time, and not allow you to flood a bunch of queries in a single request.

    In any event, I’d assume you could fix your problem in a "naive" way by having many request variables instead of just one, or maybe just creating a new request with every iteration of your loop. If you’re not worried about storing your results, and just trying to debug, you could try:

    for c in comments:
        print "building query"
        dataDict = [ ('appid', appid), ('context', c)]
        queryData = urllib.urlencode(dataDict)
        request = urllib2.Request() # I don't know how to initialize this variable, do it yourself
        request.add_data(queryData)
        print "fetching result"
        result = OPENER.open(request).read()
        print result
        time.sleep(1)
    

    Again, I don’t know about the Yahoo Term Extractor (nor do I really have time to research it) so there may very well be a better, more native way to do this. If you post more details of your code (i.e. what classes are the request and OPENER objects coming from) then I might be able to elaborate on this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through some elements in a form (radios, text boxes,
I'm trying to loop through some static properties in a simple static class in
I am trying to loop through some controls in a Powershell / WPF application.
I'm currently trying to write some Javascript to loop through the elements in a
Using Javascript. I'm trying to loop through an array encoded with JSON. Here is
I am trying to write some code that will loop through a list and
I am trying to find a way to loop through the properties of an
I'm trying to find a way to easily loop through a Google App Engine
I'm trying to loop through items of a checkbox list. If it's checked, I
I am having problems with my JScript code. I am trying to loop through

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.