0

First question, Is there a way to see what variables and object name where passed during creating class instance:

I have following classes:

class clCmd(object):
    def __init__(self, testObj, cmd=None, template=None, option=None, optionList=None):
...

class test(clCmd):
    def __init__(self, *args, **kwargs):
...
        super(test, self).__init__(*args, **kwargs)

I am using this in this way:

t_rev3_test = 'blabla'
t_rev4_test = 'hellohello'
name = 'TEST1'
revision = t_rev3_test
tc_01 = testcase(name, revision)
a = test(tc_01, template=t_rev3_test)

Where testcase class is:

class testcase(object):
    def __init__(self, name, revision):
...

Now, is there a way to see in the test class the object name 'tc_01' or the revision original variable name, so not the value that is passed but the actual name 't_rev3_test'?

My second, question is if i can find a way to compose a variable name (variable exists) from a string. I have read several other threads but couldn't figure it out how to implement it for my purpose!

example: totally simplified and not correct, i know, but something like that

t_rev3_test = 'blabla'
t_rev4_test = 'hellohello'
rev = '3'

tmp = 't_rev' + rev + '_test'
print tmp

should print: blabla

FotisK
  • 1,055
  • 2
  • 13
  • 28
  • 3
    You probably don't want to do either of these things. In your second question, at least, you most likely want to use a `dict`. – jme Sep 01 '15 at 17:08
  • @jme, thanks for your reply, i did read about using a dict! I have to see it again. What about the first question? Is there a way to see the actual name of the variable that was passed into `a = test(tc_01, template=t_rev3_test)` for template? So 't_rev3_test'!!! – FotisK Sep 01 '15 at 19:50
  • There's no way of doing it that I wouldn't consider bad, ugly, or hacky. In short, you should not write code that relies on what variables are *named* -- write code that uses the value in the variable. – jme Sep 01 '15 at 20:33

0 Answers0