parameters: (item, fields, none_string="None")
return_statement: return values
docstring: Return item values from within the given fields, converted to strings.
  
      Fields may be plain string or numeric values:
  
          >>> item_values({'name': 'sword', 'length_cm': 90},
          ...             ['name', 'length_cm'])
          ['sword', '90']
  
      Fields may also be nested objects; subkeys may be referenced like
      key.subkey:
  
          >>> item_values({'loc': {'x': 5, 'y': 10}}, ['loc.x', 'loc.y'])
          ['5', '10']
  
      Fields with a nested object list have their values combined with "/":
  
          >>> item_values({'locs': [{'x': 4, 'y': 8}, {'x': 5, 'y': 10}] },
          ...             ['locs.x', 'locs.y'])
          ['4 / 5', '8 / 10']
  
      Fields may include both plain and dotted keys:
  
          >>> item_values({'id': 'd6', 'name': {'str': 'die', 'str_pl': 'dice'}},
          ...             ['id', 'name.str', 'name.str_pl'])
          ['d6', 'die', 'dice']
docstring_summary: Return item values from within the given fields, converted to strings.
docstring_tokens: Return item values from within the given fields converted to strings .
function: def item_values(item, fields, none_string="None"):
      """Return item values from within the given fields, converted to strings.
  
      Fields may be plain string or numeric values:
  
          >>> item_values({'name': 'sword', 'length_cm': 90},
          ...             ['name', 'length_cm'])
          ['sword', '90']
  
      Fields may also be nested objects; subkeys may be referenced like
      key.subkey:
  
          >>> item_values({'loc': {'x': 5, 'y': 10}}, ['loc.x', 'loc.y'])
          ['5', '10']
  
      Fields with a nested object list have their values combined with "/":
  
          >>> item_values({'locs': [{'x': 4, 'y': 8}, {'x': 5, 'y': 10}] },
          ...             ['locs.x', 'locs.y'])
          ['4 / 5', '8 / 10']
  
      Fields may include both plain and dotted keys:
  
          >>> item_values({'id': 'd6', 'name': {'str': 'die', 'str_pl': 'dice'}},
          ...             ['id', 'name.str', 'name.str_pl'])
          ['d6', 'die', 'dice']
  
      """
      values = []
      for field in fields:
          if "." in field:
              subkeys = field.split(".")
          else:
              subkeys = [field]
          # Descend into dotted keys
          it = item
          for subkey in subkeys:
              # Is it a dict with this subkey?
              if isinstance(it, dict) and subkey in it:
                  it = it[subkey]
              # Is it a list of dicts having this subkey?
              elif isinstance(it, list) and all(subkey in o for o in it):
                  # Pull from all subkeys, or just the one
                  if len(it) == 1:
                      if isinstance(it[0], dict):
                          it = it[0][subkey]
                      else:
                          it = it[0]
                  else:
                      it = [i[subkey] for i in it]
              # Stop if any subkey is not found
              else:
                  it = none_string
                  break
  
          if isinstance(it, dict):
              if set(it.keys()) <= I18N_DICT_KEYS_SET:
                  # it dict contains only i18zed values
                  first_good_value = None
                  for k in I18N_DICT_KEYS:
                      value = it.get(k, None)
                      if value:
                          first_good_value = value
                          break
                  values.append("%s" % first_good_value or none_string)
              else:
                  # Make dict presentable
                  values.append("%s" % it.items())
          # Separate lists with slashes
          elif isinstance(it, list):
              values.append(" / ".join(
                  "%s" % i if i is not None else none_string for i in it))
          # Otherwise just force string
          else:
              values.append("%s" % it if it is not None else none_string)
  
      return values
function_tokens: def item_values ( item , fields , none_string = "None" ) : values = [ ] for field in fields : if "." in field : subkeys = field . split ( "." ) else : subkeys = [ field ] # Descend into dotted keys it = item for subkey in subkeys : # Is it a dict with this subkey? if isinstance ( it , dict ) and subkey in it : it = it [ subkey ] # Is it a list of dicts having this subkey? elif isinstance ( it , list ) and all ( subkey in o for o in it ) : # Pull from all subkeys, or just the one if len ( it ) == 1 : if isinstance ( it [ 0 ] , dict ) : it = it [ 0 ] [ subkey ] else : it = it [ 0 ] else : it = [ i [ subkey ] for i in it ] # Stop if any subkey is not found else : it = none_string break if isinstance ( it , dict ) : if set ( it . keys ( ) ) <= I18N_DICT_KEYS_SET : # it dict contains only i18zed values first_good_value = None for k in I18N_DICT_KEYS : value = it . get ( k , None ) if value : first_good_value = value break values . append ( "%s" % first_good_value or none_string ) else : # Make dict presentable values . append ( "%s" % it . items ( ) ) # Separate lists with slashes elif isinstance ( it , list ) : values . append ( " / " . join ( "%s" % i if i is not None else none_string for i in it ) ) # Otherwise just force string else : values . append ( "%s" % it if it is not None else none_string ) return values