如何在不使用" \"的情况下打破此行?
with mock.patch('six.moves.builtins.open', mock.mock_open()), mock.patch('my_module.yaml.safe_load') as mock_yaml:
#do something
我尝试使用括号,但它抱怨SyntaxError关于" as"
with (mock.patch('six.moves.builtins.open', mock.mock_open()),
mock.patch('my_module.yaml.safe_load') as mock_yaml):
#do something
答案 0 :(得分:0)
在一组括号内打破它,但没有mock.patch(....)
周围的括号,应该根据PEP8 Python Style Guide工作,因为括号之间有隐含的续行:
with mock.patch('six.moves.builtins.open',
mock.mock_open()), mock.patch('my_module.yaml.safe_load') as mock_yaml:
另一个选项类似于您的第二个建议,但是在as
之前移动了右括号:
with (mock.patch('six.moves.builtins.open', mock.mock_open()),
mock.patch('my_module.yaml.safe_load')) as mock_yaml: