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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:07:49+00:00 2026-06-01T14:07:49+00:00

Have been searching how to convert a dictionary to a string. But the results

  • 0

Have been searching how to convert a dictionary to a string. But the results found is not the ones i am looking for.
The results i currently find is basically turning the whole dictionary into a string, but i don’t really want {}, , and : in my string.
So i got a dictionary of sorted URLvars i wanted to join together again.

vars = {"id":"2", "test":"3"}

so i want a way to convert this dictionary to:

vars = "id=2&test=3"

UPDATE:
Thanks for the help. Here is also the POC i made for the larger script i am doing! Might be better ways to write this tho ;P

from urlparse import urlparse
import urllib

def main(url, var, params):
    urllenght = len(url)
    urlfind = url.find("?")
    lenght = urlfind - urllenght

    params = '&'.join(["%s=%s" % (k, v) for k, v in params.iteritems()])
    url = url[:lenght]

    print params
    print url
    print url+"?"+params

if __name__ == '__main__':
    url="http://test.com/index.php?id=2&test=2"
    url2 = urlparse(url)
    params = dict([part.split('=') for part in url2[4].split('&')])
    print "Avaible URL params"
    for k,v in params.items():
        print "Params: %s" % k

    while True:
        var = raw_input("Select param: ")
        if var in params:
            main(url, var, params)
            break
        else:
            pass
  • 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-01T14:07:50+00:00Added an answer on June 1, 2026 at 2:07 pm

    What you need, is urllib.urlencode:

    >>> import urllib
    >>> vars = {"id":"2", "test":"3"}
    >>> urllib.urlencode(vars)
    test=3&id=2
    

    But keep in mind, that it will also convert special URL symbols to their %-form. So, if you don’t want that, try simply:

    '&'.join([`%s=%s` % (k, v) for k, v in vars.iteritems()])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching everywhere but I could not find an answer. I need
I have been searching this for quite sometime but could not find an appropriate
I have been searching desperately for an answer to this question, but not found
I have been searching around using Google but I can't find an answer to
I have been searching but unable to find a proper list. Can someone please
I have been searching everywhere but can't seem to find a solution to this
I have been searching for an answer to this but can't find it on
I have been searching around for this question but cant seem to find it.
Have been searching all over the internet but struggling to find my answer to
I have been searching to a resolution to this for hours, but I still

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.