Search code examples
python-3.7odoo-12

What is the use of this line of code with [0][1] index?


i cant find out what does name_get()[0][1]

display_name = product_id.name_get()[0][1]
       if product_id.description_sale:
           display_name += '\n' + product_id.description_sale

Solution

  • Breaking it down backwards: [0][1] indicates an element of a 2d array (an array that has elements which are also arrays), so therefore we can infer that the expectation is that name_get() returns a 2d array - we can't say anything about the type of values inside those arrays though - python is dynamically typed.

    product.name_get() indicates that name_get() is a method/function of the product class/file.

    As an example - name_get() might return something like

    [ ["savings account", "current account"], ["credit card", "store card"] ]
    

    so name_get()[0][1] would evaluate to "current account"