简体   繁体   中英

using os.environ to tally and display lists

Pardon me if my title misleads you but I am having problems in trying to get a list generated accordingly to the category selected and while I can change the category, it is still retaining the values of the list in the previous category selection

category = os.environ['CAT']
item = os.environ['ITEM']

""" ezygate.Job.getItems is the code of the inhouse tool i'm using to derive the list of items """
itemList = ezygate.job.getItems({'Items': '%s'%category})

category = ['Shirts'] 
itemList = ['v-neck', 'round', 'long sleeve', ...] 

So when users wanted to change the category, they have to access another ui to change it (Not part of this coding), though the os.environ['CAT'] will be updated accordingly, the itemList is wrong... For example:

category = ['Shorts']
itemList = ['v-neck', 'round', 'long sleeve', ...]

When I tried to do a os.environ.clear() , it screws up my Maya and I have gotten the following error:

# Error: CAT
# Traceback (most recent call last):
#   File "<maya console>", line 2, in <module>
#   File "/apps/Linux64/aw/maya2014/lib/python2.7/UserDict.py", line 23, in __getitem__
#     raise KeyError(key)
# KeyError: 'CAT # 

And hence are there any ways in which the os.environ['ITEM'] will clears the itemsList if it is not part of the category ? I am looking to see if there are any other in-house codes that will reads the list of items other than using the os.environ method (which is the only one I know of...)

It looks like you've got a module ezygate , which you've made in-house. Create a dict of list s in that module, with the following structure:

cats = {'Shirt': ['v-neck', 'round', 'long sleeve']}

So long as the other ui can import ezygate , you can access the same dict there, instead of relying on os.environ

ezygate.cats['Shirt']

os.environ is a dictionary stored in the os module, but there's no reason you couldn't rely on another dictionary from another module. Depending on your modules, one may jump out more than ezygate , but the important thing is that the module be imported wherever you need to rely on the dict .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM