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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:27:49+00:00 2026-05-16T11:27:49+00:00

Usage scenario: # case #1 – for classes a = MyClass() # default logger

  • 0

Usage scenario:

# case #1 - for classes
a = MyClass() # default logger is None
a = MyClass(logger="a") # set the default logger to be "a"
a.test(logger="b") # this means that logger will be "b" only inside this method
a.test(logger=None) # this means that logger will be None but only inside this method
a.test() # here logger should defaults to the value specified when object was initialized ("a")

How can I implement MyClass in order to be able to use it as above?

Let’s assume that I have several methods inside MyClass that can accept the logger named parameter so I would appreciate a solution that does not require to add a lot of duplicate code at the beginning of each test...() method.

I read about the sentinel example, but this does not work for classes and I would not like to add a global variable to keep the sentinel object inside.

  • 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-16T11:27:50+00:00Added an answer on May 16, 2026 at 11:27 am
    _sentinel = object()
    
    class MyClass(object):
      def __init__(self, logger=None):
        self.logger = logger
      def test(self, logger=_sentinel):
        if logger is _sentinel: logger = self.logger
    
    # in case you want to use this inside a function from your module use:
    _sentinel = object()
    logger = None
    def test(logger=_sentinel)
        if logger is _sentinel: logger = globals().get('logger')
    

    two core ideas: capturing the set of named values that may be (or may not be) locally overridden into a keywords-parameters dict; using a sentinel object as the default value to uniquely identify whether a certain named argument has been explicitly passed or not (None is often used for this purpose, but when, as here, you want None as a “first class value” for the parameter, a unique sentinel object will do just as well).

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

Sidebar

Related Questions

This question shows the usage of **var = new Object(); and that's something totally
Usage scenario We have implemented a webservice that our web frontend developers use (via
Consider this scenario: Using Javascript/E4X, in a non-browser usage scenario (a Javascript HL7 integration
oftentimes I have this kind of usage scenario: entity A is connected to B
Ok so the usage scenario is as follows: I have a button that opens
What is an ObjectMother and what are common usage scenarios for this pattern?
I am working on a Java application that will use some Hibernate (annotated by
As the title states im having some difficulties analzying the average-case memory usage of
I am having some speed issue with my datatables. In this particular case I
Take a guess ... how long will this program take to produce the very

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.