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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:07:25+00:00 2026-05-12T17:07:25+00:00

I know about urllib and urlparse , but I want to make sure I

  • 0

I know about urllib and urlparse, but I want to make sure I wouldn’t be reinventing the wheel.

My problem is that I am going to be fetching a bunch of urls from the same domain via the urllib library. I basically want to be able to generate urls to use (as strings) with different paths and query params. I was hoping that something might have a syntax like:

url_builder = UrlBuilder("some.domain.com")
# should give me "http://some.domain.com/blah?foo=bar
url_i_need_to_hit = url_builder.withPath("blah").withParams("foo=bar")  # maybe a ".build()" after this

Basically I want to be able to store defaults that get passed to urlparse.urlunsplit instead of constantly clouding up the code by passing in the whole tuple every time.

Does something like this exist? Do people agree it’s worth throwing together?

  • 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-12T17:07:25+00:00Added an answer on May 12, 2026 at 5:07 pm

    Still not quite sure what you’re looking for… But I’ll give it a shot. If you’re just looking to make a class that will keep your default values and such, it’s simple enough to make your own class and use Python magic like str. Here’s a scratched-out example (suboptimal):

    class UrlBuilder:
        def __init__(self,domain,path="blah",params="foo=bar"):
            self.domain = domain
            self.path = path
            self.params = params
    
        def withPath(self,path):
            self.path = path
            return self
    
        def withParams(self,params):
            self.params = params
            return self
    
        def __str__(self):
            return 'http://' + self.domain + '/' + self.path + '?' + self.params
            # or return urlparse.urlunparse( ( "http", self.domain, self.path, self.params, "", "" )
    
        def build(self):
            return self.__str__()
    
    if __name__ == '__main__':
        u = UrlBuilder('www.example.com')
        print u.withPath('bobloblaw')
        print u.withParams('lawyer=yes')
        print u.withPath('elvis').withParams('theking=true')
    

    If you’re looking for more of the Builder Design Pattern, the Wikipedia article has a reasonable Python example (as well as Java).

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

Sidebar

Related Questions

I know about the ADODB.Stream object . But what I really want is a
I know about the WebRequest and the WebResponse objects. The problem is that I
I know about share image or text on Facebook but if i want to
I know about filter_parameter_logging for request params, but that only works for request parameters.
I know about RSA authentication, but for my purposes I want to use a
I know about Object#tap , which takes a value and returns that value. But
I know about SortedSet , but in my case I need something that implements
I know about ELMAH, but that only logs unhandled errors. I need something that
I know about http://www.upcdatabase.com/ , but it's quite incomplete. Where popular mobile apps getting
I know about primitives and objects living on the heap, but how does the

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.