![]() Your method does not give you proper difference. Your method gives us '' difference, but the both has the same keys. We need to check keys only (does the both have "f" key):. ![]() I think it's good, but not for all cases. ![]() No need for 66 lines, which are completely unrelated to Django. Now generalize the mapper and use set(mapper(json1)) - set(mapper(json2)). fast and efficient.įor lists, you might use set(enumerate(list1)) - set(enumerate(list2)). Python Django CRUD Example Tutorial by tuts_stationįor dicts, you might try to use set(eritems()) - set(eritems()) which will compute the difference for you.Month / Year SelectDateWidget based on django SelectDateWidget by pierreben.Add custom fields to the built-in Group model by jmoppel.save_diff ( ' %s - %s | %s ' % ( path, first, second ), VALUE ) return def save_diff ( self, diff_message, type_ ): message = ' %s : %s ' % ( type_, diff_message ) if diff_message not in self. else : if with_values and second != None : if first != second : self. check for equality (only if with_values is True) and return. check ( first, sec, path = new_path, with_values = with_values ) # not list, not dict. save_diff ( ' %s - %s, %s ' % ( new_path, type ( first ), type ( second )), TYPE ) # recursive call self. elif isinstance ( first, list ): for ( index, item ) in enumerate ( first ): new_path = " %s " % ( path, index ) # try to get the same index from second sec = None if second != None : try : sec = second except ( Inde圎rror, KeyError ): # goes to difference self. check ( first, second, path = new_path, with_values = with_values ) # if object is list, loop over it and check. every key from first goes to the difference self. check ( first, sec, path = new_path, with_values = with_values ) else : # second is not dict. save_diff ( new_path, PATH ) # prevent further values checking. has_key ( key ): sec = second else : # there are key in the first, that is not presented in the second self. In 2000, Salesforce and eBay launched their own API, with which programmers could access and download some of the data available to the public. %s " % ( path, key ) if isinstance ( second, dict ): if second. An API ( Application Programming Interface) is an interface that makes it much easier to develop a program by providing the building blocks. if len ( path ) = 0 : new_path = key else : new_path = " %s. save_diff ( message, TYPE ) if isinstance ( first, dict ): for key in first : # the first part of path must not have trailing dot. check ( second, first, with_values = with_values ) def check ( self, first, second, path = '', with_values = False ): if second != None : if not isinstance ( first, type ( second )): message = ' %s - %s, %s ' % ( path, type ( first ), type ( second )) self. check ( first, second, with_values = with_values ) if vice_versa : self. Class Diff ( object ): def _init_ ( self, first, second, with_values = False, vice_versa = False ): self.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |