我试图用Python在Blender中制作一个音频可视化器,我的代码一直在抛出这个语法错误。
SyntaxError:(unicode error) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape location: unknown location :-1# python file
bpy.ops.graph.sound_bake(filepath="C:\Users\Callum\Desktop\Teardrop.mp3", low= i*step, high=i*step+step)发布于 2014-02-22 00:18:52
编辑:
在这条线上:
bpy.ops.graph.sound_bake(filepath=r"C:\Users\Callum\Desktop\Teardrop.mp3", low= i*step, high=i*step+step)文件路径字符串中的\U被解释为转义序列:
>>> '\U'
File "<stdin>", line 1
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \UXXXXXXXX escape
>>>要解决这个问题,在字符串前面放置一个r:
bpy.ops.graph.sound_bake(filepath=r"C:\Users\Callum\Desktop\Teardrop.mp3", low= i*step, high=i*step+step)这将将其转换为不处理转义序列的粗串:
>>> r'\U'
'\\U'
>>>另一种解决方案是将反斜杠转换为正斜杠:
bpy.ops.graph.sound_bake(filepath="C:/Users/Callum/Desktop/Teardrop.mp3", low= i*step, high=i*step+step)即使您正在运行Windows,Python仍然可以很好地处理文件中的正斜杠。
发布于 2014-02-22 00:19:35
我看到两件事:
if c == columns:
r += 1
c = 0应该是
if c == columns:
r += 1
c = 0和
bpy.ops.graph.sound_bake(filepath="C:\Users\Callum\Desktop\Teardrop.mp3", low= i*step, high=i*step+step遗漏了结束括号。
https://stackoverflow.com/questions/21947762
复制相似问题