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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:57:42+00:00 2026-05-24T16:57:42+00:00

I am writing a simple class that will basically accept 3 parameters, execute a

  • 0

I am writing a simple class that will basically accept 3 parameters, execute a series of commands and return the result.

Now the problem is that i am not clear about how to write a proper class in Python (i use C++ mainly); so is kinda weird for me to figure out what and how to write the class.

I have 3 parameters: name, classID and objectType (all 3 strings type), i need to return a string with the results of the operation.

So far I wrote this:

class testClass(superclass):

def __init__(self, name="",classID="", objectType="" *kwargs):

    superclass.__init__(self, args, **kwargs)

    result = ""
    ...(do the operation with the parameters, if the result is positive return OK
        otherwise return KO)

Then i saved it as testClass.py and imported it in my main python program

The issue is that when i pass parameters i get an error saying that the global name “args” is not defined, on the superclass __init line

In C I would just write something like

class testClass 
{
    string name, classID, objectType;
}string

and the program would know that it must expect 3 parameters (and then deal in the constructor with the data verification and validation), but i cannot grasp how you tell Python the same thing.

If i can get to understand how to use Python in the way that it should be (and not translating code from a language to another), maybe i can avoid to get stuck like in this case 🙂

Any help is appreciate to shed some light on the subject.

  • 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-24T16:57:43+00:00Added an answer on May 24, 2026 at 4:57 pm

    I think what you are looking for is the function definition thats like this def __init__(self, name="", classId="", objectType="", *args, **kwargs):.

    What this defines besides the 3 known arguments (name, classId, objectType) is args which is a list of addtional arguments passed to the function, and kwargs which is a dictionary containing named arguments passed to the function.

    With the above definition for your __init__ you could call your class this way:

    t = testClass("name", "class1", "Object", "value1", 11, scope="local", destroy=True)
    

    Now that call would give us inside __init__

    name = "name"
    classId= "class1"
    objectType = "Object"
    args =  ["value1", 11]
    kwargs = { 'scope': "local",
               'destroy': True }
    

    Oh and lastly, *args, **kwargs is optional for any function definition. If like you mention you know you will only be passed 3 arguments, then you can remove the *args, **kwargs.

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

Sidebar

Related Questions

For example, I'm writing tests against a CsvReader. It's a simple class that enumerates
I'm writing an application using gtkmm. I wrote a simple widget class, that I
I'm writing a simple C++ class in which I would like cache picture thumbnails
I'm writing a simple OpenGL application that uses GLUT . I don't want to
I'm writing a simple app that's going to have a tiny form sitting in
I am currently writing a simple, timer-based mini app in C# that performs an
I am writing a simple Python web application that consists of several pages of
I'm writing a simple tool for troubleshooting computers. Basically its just a WPF Window
I am writing a series of batch files to demonstrate to my class what
How long does it take for an experienced Windows programmer to learn writing simple

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.