Hello Justin,

The config object does not require there to be a first class attribute at
the moment, this however may be subject to change later so a dictionary
will be used if this is the case.

The getattr method seems to be working well for me so far

-- Ben

On 25 March 2015 at 11:01, Justin Israel <[email protected]> wrote:

> I don't know much about what type of object your config instance is (you
> referred to is as a config file global list), but maybe what you want is a
> dictionary? Sometimes it is very useful to be able to access attributes
> dynamically via string names, and sometimes people try to do it in place of
> really just using a dict for the variable key names.
> It may be a completely wrong suggestion for what you are doing, but does
> the type of this config object require there to be first class attributes?
> If the Config object is what it is and you can't really change the way it
> exposes values, then maybe the getattr approach is the right choice to map
> string attribute names from an xml to an object.
>
> On Wed, 25 Mar 2015 10:05 PM Benjam901 <[email protected]> wrote:
>
>> Hello again,
>>
>> So after looking at the problem with fresh eyes, I have come across the
>> getattr and setattr functions within python.
>>
>> I think I may have cracked it, some initial tests show positive results.
>>
>> I used getattr(config, configVar).append(object) which seems to have
>> worked really well opposed to using setattr(config, configVar, object)
>> which seemed to give the equivalent of config.configVar = object rather
>> than appending.
>>
>> As far as general project setup goes however is it advised to using
>> config/project wide variables?
>>
>> Cheers,
>>
>> Ben
>>
>>
>> On Wednesday, 25 March 2015 09:45:19 UTC+1, Benjam901 wrote:
>>>
>>> Hello all,
>>>
>>> I am currently trying to append to a config file global list and have
>>> the need to do so using another variable. My problem is as such:
>>>
>>> I am iterating through my objects I am placing in my treeview and and
>>> checking them against an XML file that has as the tag the string I need to
>>> check for and as the attributes the name of the list I need to append to. I
>>> need to be able to access the config."list name" using a variable.
>>>
>>> For example rather than using config.modelGraphics.append(object) I
>>> would be using config."variable_name".append(object)
>>>
>>> Is this possible or do I have to use some sort of getter/setter function
>>> rather than trying to directly access my variable?
>>>
>>> My code is listed below.
>>>
>>> Cheers,
>>>
>>> Ben
>>>
>>>     def checkAssetDefinition(self, object, fileType):
>>>             object = str(object)
>>>             for attr in self.xmlAssetDefsList:
>>>                     if object.startswith(attr):
>>>                             innerDict = self.xmlAssetDefsList.get(attr)
>>>                             for myType in innerDict:
>>>                                     if myType == fileType:
>>>                                             configVar = 
>>> innerDict.get(myType)
>>>                                             config.configVar.append(myType) 
>>> ???
>>>                                             # Need to get the config 
>>> variable from the config list variable
>>>
>>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/497423a5-e64e-4ee0-b5a8-ff367448c6db%40googlegroups.com
>> <https://groups.google.com/d/msgid/python_inside_maya/497423a5-e64e-4ee0-b5a8-ff367448c6db%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Python Programming for Autodesk Maya" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python_inside_maya/sWXrW8kfsUE/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1a2pHka-D5Bxn4K%3DpY1v9rbHQiK0yu_GkE9rmpVyUjJw%40mail.gmail.com
> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1a2pHka-D5Bxn4K%3DpY1v9rbHQiK0yu_GkE9rmpVyUjJw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 

Tel - +46 76245 92 90 (Sweden)
LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkVkPO362DrOe%2BcUjUyLisL5Udw-SdH-g-hnEaGVuXuT3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to