例如,如果我有
>>> name = f"{os.path.splitext(os.path.basename('/some/long/path/I/donot/need/to/some/config.bs'))[0]}.yaml"
'config.yaml'
因为实际文本很少,所以在 79 个字符之前没有好地方可以换行。看来你不能这样做:
name = f"{os.path.splitext(os.path.basename(
'/some/long/path/I/donot/need/to/some/config.bs'))[0]}.yaml"
>>> f"{os.path.splitext(os.path.basename(
File "<stdin>", line 1
f"{os.path.splitext(os.path.basename(
^
SyntaxError: EOL while scanning string literal
我唯一能做的就是拆分命令,例如:
>>> fname = '/some/long/path/I/donot/need/to/some/config.bs'
>>> tempname = os.path.splitext(os.path.basename(
... fname))[0]
>>> name = f'{tempname}.yaml'
>>> name
'config.yaml'
是否有任何其他选项来拆分 f 字符串?