【问题标题】:What is the use of this line of code with [0][1] index?这行带有 [0][1] 索引的代码有什么用?
【发布时间】:2019-09-19 13:50:09
【问题描述】:

我不知道 name_get()[0][1] 是什么意思

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

【问题讨论】:

    标签: python-3.7 odoo-12


    【解决方案1】:

    向后分解:[0][1] 表示二维数组的一个元素(一个数组,其元素也是数组),因此我们可以推断出预期是 name_get() 返回一个二维数组 - 我们可以不过,不要说这些数组中的值的类型 - python 是动态类型的。

    product.name_get()表示name_get()是产品类/文件的方法/函数。

    例如 - name_get() 可能会返回类似

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

    所以name_get()[0][1] 将评估为"current account"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多