Python Forum
calling an object variable in a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
calling an object variable in a dictionary
#3
I'm not sure what you are trying to do, but think it's something like this:
(this done in Python 3.5, can't stand 2.7 it's toooooo old
class char(object):
    'chactors'

    # Create instances of object
    def __init__(self, name, d):
        self.name = name
        self.d = int(d)
        self.statlist = {'mov': d, 'act': d}
        self.skillmap = {'mov': 'self.mov'}
        print('self.statlist: {}'.format(self.statlist))
        print('self.skillmap: {}'.format(self.skillmap))
        self.satmap = {'d': 'self.d'}
        self.skillint = None

    def action(self, skill):
        if skill in self.statlist:
            print('self.statlist[skill]: {}'.format(self.statlist[skill]))

def main():
    char1 = char('q', '1')
    char1.statlist['mov'] = 10
    char1.statlist['act'] = 200

    char1.action('mov')
    char1.action('act')

if __name__ == '__main__':
    main()
results:
Output:
self.statlist: {'mov': '1', 'act': '1'} self.skillmap: {'mov': 'self.mov'} self.statlist[skill]: 10 self.statlist[skill]: 200 Process finished with exit code 0
Reply


Messages In This Thread
RE: calling an object variable in a dictionary - by Larz60+ - Dec-29-2016, 05:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling functions by making part of their name with variable crouzilles 4 891 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,046 Jul-23-2021, 04:18 PM
Last Post: jacknewport
  Defining an object's argument whose name is stored in a variable arbiel 2 2,227 Dec-11-2020, 10:19 PM
Last Post: arbiel
Bug maximum recursion depth exceeded while calling a Python object error in python3 Prezess 4 3,811 Aug-02-2020, 02:21 PM
Last Post: deanhystad
  variable as dictionary name? diazepam 4 11,336 Apr-27-2020, 08:11 AM
Last Post: deanhystad
  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
  zip file variable prints <zipfile.ZipFile object at 0x7f83fd13bd90> ? Rsh 9 4,262 Jun-27-2019, 02:00 PM
Last Post: Rsh
  Reference new dictionary keys with a variable slouw 4 2,951 May-07-2019, 03:30 AM
Last Post: slouw

Forum Jump:

User Panel Messages

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