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

  • Home
  • SEARCH
  • 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 8833011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:40:33+00:00 2026-06-14T08:40:33+00:00

Here is a class Class A: def __init__(self, a, b): self.a = a self.b

  • 0

Here is a class

Class A:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def set_value(self,"attribut_String",value):   # passing a attribute in String
        if "attribut_String" = "AAAA":
            self.cal_function("a",value) 
        else "attribut_String" = "BBBB":
            self.cal_function("b",value) 

    def cal_function(self,att,value):
        self.att = value       # process the passing string as attribute object

Now , i’m try to a result like this :

input:rlt = A(a = 1, b = 2)
input:rlt.a
output: 1
input:rlt.set_value("a",3)
input:rlt.a
output:4

May it seems unnecessary because I simplified the scenario . I have to code in this way

  • 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-14T08:40:34+00:00Added an answer on June 14, 2026 at 8:40 am

    You can use a control flow inside your set_value function:

    def set_value(self, member, value):
        if member == "a":
            self.a = value
        elif member == "b":
            self.b = value
    

    If you don’t mind dropping the set_value function, you can use the setattr function:

    setattr(myobject, "a", value)
    

    or even

    def set_value(self, member, value):
        setattr(self, member, value)
    

    You can also use a dictionary:

    def set_value(self, member, value):
        members = {
            "a" : self.a,
            "b" : self.b
        }
        members[member] = value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: class MyTestCase(Base): def setUp(self): #some code here def test_B(self): #some
Here is what I want to do: class demo(object): def a(self): pass def b(self,
class HelloWorld(object): def say_it(self): return 'Hello I am Hello World' def i_call_hello_world(hw_obj): print 'here...
Here is a related manager I wrote: class PortfolioItemManager(models.Manager): use_for_related_fields = True def extended(self):
class Adder: result = 0 def __init__( self, number1, number2 ): self.result = int(
I have code like the following: class SomeSharedData(object): def __init__(self): self._lock = RLock() self._errors
Here is some code: class Person def initialize(age) @age = age end def age
Here's some example code: class Obj attr :c, true def == that p '=='
Here's a simple migration I'd like to run : class AddTimeOfRevisionToBrandWikis < ActiveRecord::Migration def
I found this code here class Usable; class Usable_lock { friend class Usable; private:

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.