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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:09:40+00:00 2026-06-13T06:09:40+00:00

imagine the following scenario: class A: def __init__(self, arg1=3, arg2=5): pass def createA(arg1=None, arg2=None):

  • 0

imagine the following scenario:

class A:
    def __init__(self, arg1=3, arg2=5):
        pass

def createA(arg1=None, arg2=None):
    if arg1 is None:
        if arg2 is None:
            a = A()
        else:
            a = A(arg2=arg2)
    else:
        if arg2 is None:
            a = A(arg1=arg1)
        else:
            a = A(arg1=arg1, arg2=arg2)
    return a

Whats the best way to implement this behavior, with the followings in mind:

  • I can’t/don’t want to change class A
  • I don’t want to explicitly add the default values of A‘s constructor’s parameters to the createA function?

For example is there any value that indicates a not passed optional argument?
Something like:

if arg1 is None:
    newArg1 = NotPassed
else:
    newArg1 = arg1

if arg2 is None:
    newArg2 = NotPassed
else:
    newArg2 = arg2
A(arg1=newArg1, arg2=newArg2)
  • 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-13T06:09:42+00:00Added an answer on June 13, 2026 at 6:09 am
    def create_A(arg1=None, arg2=None):
        kwargs = {}
        if arg1 is not None: kwargs['arg1'] = arg1
        if arg1 is not None: kwargs['arg2'] = arg2
        return A(**kwargs)
    

    or maybe even

    def create_A(**kwargs):
        return A(**kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine the following scenario: class MyClass extends OtherClass<String>{ String myName; //Whatever } class OtherClass<T>
Imagine the following scenario: template<class T> void myFunction(T *) { //do nothing } void
Imagine following scenario: We have a lot of parallel development going on in several
Imagine the following class that manages a resource (my question is only about the
I am curious how to document the following scenario. Imagine a group of classes:
Imagine the following scenario: some xml file is downloaded from server and stored on
Imagine the following scenario: I am using SQL Server 2005. I have a transaction
Imagine the following scenario: You are asked to develop a tool from scracth, by
Imagine the following scenario. User visits a site A (ASP.NET), authenticates using ADFS and
Possible Duplicate: Does a finally block always run? let's imagine the following scenario: public

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.