def main(client, custom_field_id, drop_down_custom_field_id,
         custom_field_option_id, line_item_id):
  # Initialize appropriate services.
  custom_field_service = client.GetService(
      'CustomFieldService', version='v201508')

  line_item_service = client.GetService('LineItemService', version='v201508')

  # Create statement to get a custom field.
  custom_field_values = [{
      'key': 'customFieldId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': custom_field_id
      }
  }]
  custom_field_query = 'WHERE id = :customFieldId'
  custom_field_statement = dfp.FilterStatement(
      custom_field_query, custom_field_values, 1)

  # Get custom field.
  custom_field = custom_field_service.getCustomFieldsByStatement(
      custom_field_statement.ToStatement())['results'][0]

  # Create statement to get a drop down custom field.
  drop_down_custom_field_values = [{
      'key': 'dropDownCustomFieldId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': drop_down_custom_field_id
      }
  }]
  drop_down_custom_field_query = 'WHERE id = :dropDownCustomFieldId'
  drop_down_custom_field_statement = dfp.FilterStatement(
      drop_down_custom_field_query, drop_down_custom_field_values, 1)

  # Get drop-down custom field.
  drop_down_custom_field = custom_field_service.getCustomFieldsByStatement(
      drop_down_custom_field_statement.ToStatement())['results'][0]

  # Create statement to get a line item.
  line_item_values = [{
      'key': 'lineItemId',
      'value': {
          'xsi_type': 'NumberValue',
          'value': line_item_id
      }
  }]
  line_item_query = 'WHERE id = :lineItemId'
  line_item_statement = dfp.FilterStatement(
      line_item_query, line_item_values, 1)

  # Get line item.
  line_item = line_item_service.getLineItemsByStatement(
      line_item_statement.ToStatement())['results'][0]

  if custom_field and line_item:
    # Create custom field values.
    custom_field_value = {
        'customFieldId': custom_field['id'],
        'xsi_type': 'CustomFieldValue',
        'value': {
            'xsi_type': 'TextValue',
            'value': 'Custom field value'
        }
    }

    drop_down_custom_field_value = {
        'customFieldId': drop_down_custom_field['id'],
        'xsi_type': 'DropDownCustomFieldValue',
        'customFieldOptionId': custom_field_option_id,
    }

    custom_field_values = [custom_field_value, drop_down_custom_field_value]

    old_custom_field_values = []
    if 'customFieldValues' in line_item:
      old_custom_field_values = line_item['customFieldValues']

    # Only add existing custom field values for different custom fields than the
    # ones you are setting.
    for old_custom_field_value in old_custom_field_values:
      if (old_custom_field_value['customFieldId'] !=
          custom_field_value['customFieldId']
          and old_custom_field_value['customFieldId'] !=
          drop_down_custom_field_value['customFieldId']):
        custom_field_values.append(old_custom_field_value)

    line_item['customFieldValues'] = custom_field_values

    # Update the line item on the server.
    line_items = line_item_service.updateLineItems([line_item])

    # Display results.
    for line_item in line_items:
      custom_field_value_strings = []
      for value in line_item['customFieldValues']:
        if dfp.DfpClassType(value) > 'CustomFieldValue':
          custom_field_value_string = (
              '{ID: \'%s\', value: \'%s\'}'
              % (value['customFieldId'], value['value']['value']))
        elif dfp.DfpClassType(value) == 'DropDownCustomFieldValue':
          custom_field_value_string = (
              '{ID: \'%s\', custom field option ID: \'%s\'}'
              % (value['customFieldId'], value['customFieldOptionId']))
        custom_field_value_strings.append(custom_field_value_string)
      print ('Line item with ID \'%s\' set with custom field values %s.'
             % (line_item['id'], ','.join(custom_field_value_strings)))
  else:
    print 'Line item or custom field not found.'
dataset/ETHPy150Open googleads/googleads-python-lib/examples/dfp/v201508/custom_field_service/set_line_item_custom_field_value.py/main/operator `==` -> `>`