python-3.7 - 这行带有 [0][1] 索引的代码有什么用?
问题描述
我不知道 name_get()[0][1] 是什么
display_name = product_id.name_get()[0][1]
if product_id.description_sale:
display_name += '\n' + product_id.description_sale
解决方案
向后分解:[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"
推荐阅读
- microsoft-graph-api - 有没有办法使用 Outlook Rest API 列出用户的共享邮箱?
- javascript - 如何使用 jQuery 调用 vbscript 函数?
- regex - 将提取的文本字符串转换为 Postgres 中字符串长度不同的日期
- android - Using Firebase in a multi-module project
- xslt-1.0 - How to remove Namespaces when copying nodes to a different node in XML through XSLT1.0?
- javascript - 有什么方法可以与 graphql 查询字段相反?
- python - About custom operations in Tensorflow and PyTorch
- javascript - Having pagination issue in Vue / Laravel
- php - Laravel AdminLTE - How to call method and use its data in view
- git - 在gerrit中重命名一个分支