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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:28:28+00:00 2026-05-30T13:28:28+00:00

Suppose we have the following code. I want to swap out the inner parse_place

  • 0

Suppose we have the following code. I want to swap out the inner parse_place function. How do you do this without replacing the whole method?

class GoogleV3Place(GoogleV3):
    """Simply extends the GoogleV3 to bucket the object into a place"""

    def parse_json(self, page, exactly_one=True):
        """Returns location, (latitude, longitude) from json feed."""
        if not isinstance(page, basestring):
            page = util.decode_page(page)
        self.doc = json.loads(page)
        places = self.doc.get('results', [])

        if not places:
            check_status(self.doc.get('status'))
            return None
        elif exactly_one and len(places) != 1:
            raise ValueError(
                "Didn't find exactly one placemark! (Found %d)" % len(places))

        def parse_place(place):
            """This returns an object how we want it returned."""
            location.formatted_address = place.get('formatted_address')
            location.latitude = place['geometry']['location']['lat']
            location.longitude = place['geometry']['location']['lng']

            latitude = place['geometry']['location']['lat']
            longitude = place['geometry']['location']['lng']
            return (location, (latitude, longitude))

        if exactly_one:
            return parse_place(places[0])
        else:
            return [parse_place(place) for place in places]
  • 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-30T13:28:29+00:00Added an answer on May 30, 2026 at 1:28 pm

    If you have control over the GoogleV3Place code (ie it’s code you’ve written and isn’t in a library), then I’d refactor parse_json to take a “parse_place_fn” argument, and move parse_place to be a top-level function (if accessibility is an issue you can always prefix it with double-underscore):

    def parse_place(place):
        """This returns an object how we want it returned."""
        location.formatted_address = place.get('formatted_address')
        location.latitude = place['geometry']['location']['lat']
        location.longitude = place['geometry']['location']['lng']
    
        latitude = place['geometry']['location']['lat']
        longitude = place['geometry']['location']['lng']
        return (location, (latitude, longitude))
    
    class GoogleV3Place(GoogleV3):
        """Simply extends the GoogleV3 to bucket the object into a place"""
    
        def parse_json(self, page, exactly_one=True, parse_place_fn = parse_place):
            """Returns location, (latitude, longitude) from json feed."""
            if not isinstance(page, basestring):
                page = util.decode_page(page)
            self.doc = json.loads(page)
            places = self.doc.get('results', [])
    
            if not places:
                check_status(self.doc.get('status'))
                return None
            elif exactly_one and len(places) != 1:
                raise ValueError(
                    "Didn't find exactly one placemark! (Found %d)" % len(places))
    
            if exactly_one:
                return parse_place_fn(places[0])
            else:
                return [parse_place_fn(place) for place in places]
    

    Now any function you create which takes a place and returns a tuple of the form (location, (latitude, latitude)) can be passed to parse_json, and if no function is specified it uses the default of parse_place.

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

Sidebar

Related Questions

suppose I have the following data cluster1:d(A),f(C)s,(A) cluster2:r(D),h(D),f(A) I want this out put output:
Suppose I have the following code function myFunction(param, callback) { ... if (err) {
Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose I have the following python code: def outer(): string = def inner(): string
Suppose I have the following code: trait Trait1 { trait Inner { val name
I have the following code: $(#scheduleLink).trigger(click); alert(text) This is the click handler: $(#scheduleLink).bind(click, (function
Suppose I have the following DOM : <div id=container> <div id=created-by-other-tools>I want this to
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =

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.