gpt4 book ai didi

Python 2to3 在函数参数周围添加额外的括号

转载 作者:太空狗 更新时间:2023-10-29 21:51:51 26 4
gpt4 key购买 nike

我有点困惑,为什么 2to3 会费心将我的打印参数包含在一组额外的括号中,这些参数已经是函数式风格。例如

print("\t[Warn] Can not connect {}".format(ssid))

成为

print(("\t[Warn] Can not connect {}".format(ssid)))

这些本质上是保守的误报吗?我在想也许格式函数中的尾随 ) 正在抛出它的逻辑。

最佳答案

来自文档

When the -p is passed, 2to3 treats print as a function instead of a statement. This is useful when from future import print_function is being used. If this option is not given, the print fixer will surround print calls in an extra set of parentheses because it cannot differentiate between the print statement with parentheses (such as print ("a" + "b" + "c")) and a true function call.

2to3 Docs

关于Python 2to3 在函数参数周围添加额外的括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49020649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com