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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:39:28+00:00 2026-06-15T17:39:28+00:00

Following is the code block that is working as expected. for key in context:

  • 0

Following is the code block that is working as expected.

   for key in context:
        if isinstance(context[key],collections.Iterable):
            queryString += '%s=%s&' % (key, urllib.quote(context[key]))
        else:
            queryString += '%s=%s&' % (key, context[key])
    return queryString

But I did not understand the use of if block. Shouldn’t the following work?

for key in context:
    queryString += '%s=%s&' % (key, context[key])
return queryString
  • 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-15T17:39:28+00:00Added an answer on June 15, 2026 at 5:39 pm

    It is basically saying “quote anything that isn’t numeric or a sequence when converting to a string representation”. It escapes characters to make them urlencoded.

    The if will prevent it from quoting int, float, etc, because those would crash the quote function.

    context = {'a': 'a b c', 'b': ('a', '@', 'c'), 'c': 1}
    queryString = ''
    
    for key in context:
        if isinstance(context[key],collections.Iterable):
            queryString += '%s=%s&' % (key, urllib.quote(context[key]))
        else:
            queryString += '%s=%s&' % (key, context[key])
    
    print queryString
    # a=a%20b%20c&c=1&b=a%40c&
    

    Though it only makes sense depending on what your potential inputs could be (the value of context). It would crash on say, a list of ints.

    Not using quote would look like this:

    for key in context:
        queryString += '%s=%s&' % (key, context[key])
    
    # invalid url format
    # a=a b c&c=1&b=('a', '@', 'c')&
    

    And running the quote on everything would result in:

    for key in context:
        queryString += '%s=%s&' % (key, urllib.quote(context[key]))
    ...
    TypeError: argument 2 to map() must support iteration
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is a code block that's working fine as regards getting the data
I have the following block of jQuery code that I'm using to copy some
I have following code that uses using block on TableHeaderCell , LiteralControl , HyperLink
Hi I have following code block public class Driver { static String x =
I have the following code block, as the content of my AppDelegate.h of an
I have the following code block for validation in PHP and I can't figure
I'm really stuck on why the following code block 1 result in output 1
Today I was met the following code block: #include <iostream> using namespace std; char
I need syntax help with the following code logic: I have a code block
I am trying to update values in a column like the following code block

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.