在做python单元测试时,发现有一行代码出现了错误:line too long
因此,需要将下面的长行拆分成两行:
with mock.patch('mix.driver.smartgiant.common.ipcore.mix_watch_i2c_emulator_sg.MIXWatchI2CEmulatorSG.reset_ram') as mock_reset_ram:
这里可以利用 反斜杠\ 拆分成两行,这样问题就解决了。
with mock.patch('mix.driver.smartgiant.common.ipcore.mix_watch_i2c_emulator_sg.\
MIXWatchI2CEmulatorSG.reset_ram') as mock_reset_ram:
总结:
python将一行长代码拆分成多行代码,常用有三种方法:
1、行末加反斜杠\
a = 10 + 20
等价于:
a = 10 + \
20
2、小括号括起来
b = 10 + 20
等价于:
b = (10 +
20)
3、三个单引号括起来(只对字符串有效)
c = 'abcdef'
等价于
c = '''abc
def'''