Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling a variable by name
#1
my code is: 

class char(object):
    'chactors'
 
    def __init__(self,name,d,i):
        self.name = name
        self.d = int(d)
    
    def namechar(self):
        print self.name
 
    def action(self,skill):
        if in listd:

            stat = d
        elsif in listi:
            stat =i
        else:
            pass
        t = skill + stat
        print t

    listd =['mov']
    listi =['act']

char1 = char('q','1','2')
 
setattr(char1, "mov", 10)
setattr(char1,'act', 100)
 
print char1.mov
 
char1.action('mov')
char1.action('act')
What I am trying to do:

to have a method/function that will add 2 valuables together and print the result.how ever each time i call one variable i want to add it add it to an other variable no mater which object it call on. for example i want to all add the variable 'mov' to be added to d and the variable 'act' to i. so it seams unnecessary to enter both.  instead  have the program figure out the other. for example if i called i call it on 'mov' for to figure out i needs to add it to 'd'.I am trying to do to it with a if then statement and  looking up a variable in a list. how ever i need to to know it looking for variable name and not the value. from what i here it hard to do how do i do or achieve the same things with a different means.
Reply


Messages In This Thread
calling a variable by name - by sunhear - Oct-14-2016, 08:49 PM
RE: calling a variable by name - by Yoriz - Oct-14-2016, 09:56 PM
RE: calling a variable by name - by micseydel - Oct-14-2016, 09:58 PM
RE: calling a variable by name - by ichabod801 - Oct-14-2016, 10:34 PM
RE: calling a variable by name - by sunhear - Oct-16-2016, 07:46 PM
RE: calling a variable by name - by nilamo - Oct-17-2016, 04:56 PM
RE: calling a variable by name - by metulburr - Oct-17-2016, 12:15 AM
RE: calling a variable by name - by ichabod801 - Oct-17-2016, 08:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling functions by making part of their name with variable crouzilles 4 892 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  Calling a base class variable from an inherited class CompleteNewb 3 1,751 Jan-20-2022, 04:50 AM
Last Post: CompleteNewb
Question Calling on a Variable using other Variables jacknewport 4 2,047 Jul-23-2021, 04:18 PM
Last Post: jacknewport
  Function Recognises Variable Without Arguments Or Global Variable Calling. OJGeorge4 1 2,294 Apr-06-2020, 09:14 AM
Last Post: bowlofred
  calling a variable in a for loop in windows dwaynes 1 1,839 Apr-02-2020, 05:21 PM
Last Post: mcmxl22
  calling an object variable in a dictionary sunhear 3 4,352 Dec-30-2016, 05:28 PM
Last Post: sunhear

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020