test_dict = defaultdict(list)
# Old : msg = ""msgA = msgB = msgC = None
# Inputsif all((input_01, input_02)) == False: msgA = "One or both of the Input fields is/ are empty!"elif input_01 == input_02: msgA = "Inputs used in both fields are the same!"else: msgA = validate_inputs( (input_01, input_02) )test_dict["Input Issue"].append(msgA)
# Frame Rangesstart = int(start_frame)end = int(end_frame)if (start > end) or (end < start): msgB = ( "Value of Start/Min Frame is larger than the value of " "End/Max Frame." )elif start == end: msgB = ( "Frame Values are the same" )test_dict["Frame Range Issue"].append(msgB)
# Selectionsif user_selections: msgC = validate_user_selections( input_01, user_selections )test_dict["Selections Issue"].append(msgC)
# Iterates and prints out all error at a goif test_dict: err_popup = QtGui.QMessageBox() err_popup.setIcon(QtGui.QMessageBox.Critical) err_popup.setWindowTitle("Errors found!") err_popup.setText("Please rectify the following errors found.")
err_popup.setDetailedText( "\n".join("{}\n * {}".format(k, '\n\t'.join(v)) for k, v in test_dict.items()) ) """ # This will prints out in the following format if there are values found in each key
Input Issue xxx xxx Frame Range Issue xxx Selections Issues xxx
# If there are no values (no errors) in Frame Range, it will be ouputted as Input Issue xxx xxx Selections Issues xxx """
err_popup.setStandardButtons(QtGui.QMessageBox.Ok) err_popup.exec_()
"""# Old - Only prints one error that it found in a top-down mannerif msg: err_popup = QtGui.QMessageBox() err_popup.setIcon(QtGui.QMessageBox.Critical) err_popup.setWindowTitle("Errors found!") err_popup.setText(msg) err_popup.setStandardButtons(QtGui.QMessageBox.Ok) err_popup.exec_()"""
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/d4a69a96-087e-489c-b294-0a07d609c67f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
{'Frame Range Issue': [None, 'Value of Start/Min Frame is larger than the value of End/Max Frame.'], 'Namespace Issue': [None, None], 'Selections Issue': [None, 'Value of Start/Min Frame is larger than the value of End/Max Frame.']}
appending string literals to the dictionary directly
Hi Justin, thanks for the reply.I use msg{A,B,C} because if any one of the condition passed, the msg will get appended with the next in-line error.Eg. If only frame range fails, my `test_dict` will return as follows:
{'Frame Range Issue': [None,'Value of Start/Min Frame is larger than the value of End/Max Frame.'],'Namespace Issue': [None, None],'Selections Issue': [None,'Value of Start/Min Frame is larger than the value of End/Max Frame.']}
And hence my usage of A,B,C to differentiate them as I can't reuse the same variable in which I am using defaultdict to differentiate them in this case.
appending string literals to the dictionary directlyCould you kindly elaborate more on this?
# Example 1
if all((input_01, input_02)) == False
:
msg = "One or both of the Input fields is/ are empty!"
elif input_01 == input_02:
msg = "Inputs used in both fields are the same!"
else:
msg = validate_inputs((input_01, input_02))
if msg:
test_dict["Input Issue"].append(msg)
if next_test():
msg = 'error'
if msg:
test_dict["Frame Range Issue"].append(msg)
# Example 2
append = test_dict["Input Issue"].append
if all((input_01, input_02)) == False
:
append("One or both of the Input fields is/ are empty!")
elif input_01 == input_02:
append("Inputs used in both fields are the same!")
else:
append(validate_inputs((input_01, input_02)))
append = test_dict["Frame Range Issue"].append
if next_test():
append('error')
In general, I am trying to find out what is the best practice to go about doing them :)
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/c40099fc-dce8-4987-a367-77c3616bae50%40googlegroups.com.
I was not aware that you could use `append = test_dict["Input Issue"].append` as you have demonstrated in Example #2.Learnt something new today :D
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/0d3950d2-41a1-4618-91b3-643d9836b00a%40googlegroups.com.
I have 2 questions, should have done more testing on my end..1. I am trying to understand the use of `.append'. I know that it adds things to list, but when I was looking thru the documentation page - https://docs.python.org/2/library/collections.html, even in the example, it is mostly `dict_name['key name'].append(value)` but nowhere near the method you have used.. Am I looking at the wrong doc?
2. For Method #2 you have proposed, instead of using a defaultdict(list), I used a normal dictionary {} and I got the KeyError message.Is this because when using normal dictionary, generally it should be `dict_name['key name'] = value`, and since we are not doing this way and hence the error?
Pardon the noob questions as I am trying to make sense of things
--
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 python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3a7ad9d5-118b-4617-9806-e5189992b15d%40googlegroups.com.