![](/img/trans.png)
[英]I have defined a function with two outputs and returns a list. how can I call for one of the outputs in the minimize function?
[英]How to format the a long line in python where a function call returns multiple outputs and I have to receive them?
所以我在python中有以下行:
for category in SomeLongClass.license_categories:
data[f"Category {category}"], data[f"Category {category} Validity Date"], data[f"Category {category} Expiry Date"] = SomeLongClass.get_category_dates(text_lines=text_lines, category=category)
正如你所看到的,这条线很长,而且在可读性上有所妥协。 我在这个文件上运行了 pylint,它只是告诉我这一行很长,但没有告诉我如何补救。 我试着用谷歌搜索它,它说只放一个\\
并换一个新行,但在这种情况下,这不会更损害可读性吗?
如何格式化这一行?
这是我的工作小组所做的一种方式:对齐接收变量,对齐行延续(不是严格的 PEP-8),并缩进 RHS。
# Assign three return values to the desired variables.
data[f"Category {category}"], \
data[f"Category {category} Validity Date"], \
data[f"Category {category} Expiry Date"] = \
SomeLongClass.get_category_dates(text_lines=text_lines, category=category)
我想你想要换行符。 它应该是
for category in SomeLongClass.license_categories:
(data[f"Category {category}"], \
data[f"Category {category} Validity Date"], \
data[f"Category {category} Expiry Date"]) = SomeLongClass.get_category_dates(text_lines=text_lines, category=category)
尝试分配给不同的变量,然后分配给这些变量
for category in SomeLongClass.license_categories:
a1, a2, a3 = SomeLongClass.get_category_dates(text_lines=text_lines,
category=category)
data[f"Category {category}"] = a1
data[f"Category {category} Validity Date"] = a2
data[f"Category {category} Expiry Date"] = a3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.