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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:33:06+00:00 2026-06-03T02:33:06+00:00

This was an interview question which was asked to me. Please do not penalize

  • 0

This was an interview question which was asked to me. Please do not penalize me if it doesn’t make sense. She asked:

“I have an existing 3rd party lib in python and there is a function foo() in it. How do I modify that function after importing in my existing module?”

  • 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-03T02:33:07+00:00Added an answer on June 3, 2026 at 2:33 am

    This is called monkey-patching. In short, you can just assign to the variable holding the function:

    import existingmodule
    
    existingmodule.foo = lambda *args, **kwargs: "You fail it"
    

    This is rarely the right answer in practice. It’s much better to wrap something with your own function, or provide your own implementation elsewhere, or use inheritance (if a method on a class).

    The only reason to do this is if you need the altered behaviour to be reflected in the library’s own code (or other third party code); if so, test well. It’s usually a better approach than just creating your own fork; that said, it might be a good idea to submit your code as a patch, so it’s not just you supporting it if it is accepted by the project.

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

Sidebar

Related Questions

This is an interview question. I have K machines each of which is connected
In an interview this is the question that is asked: You have to write
Note: This was an interview question and may not have an actual use case
This question was recently asked to me in an interview for which i went
This is a interview Question which was asked and wanted to find an efficient
This is the interview question asked. Which is the most important factor while drawing
This question was asked to me in an interview: Lets say you have a
Got asked this interesting interview question today. Explain in detail the process by which
I was asked this question in interview. Which of the following is better to
This is a question I was asked at my interview recently: Which 'Random' object(s)

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.