我有一个名为source的列表,我存储了文件名。现在基于每个文件的扩展名,我希望它复制到不同的文件夹。我知道这是一项非常简单的任务,但不知怎的,我没有得到它。她是我的代码:
import shutil , os
source = ['test_sound.wav','ts.raw']
src= '/home/GM/codec_implement/Audio_files'
destination1= '/home/GM/codec_implement/raw_files'
destination2= '/home/GM/codec_implement/raw_files/wave_files'
for files in source:
fileName, fileExtension = os.path.splitext(files)
if (fileExtension=='.raw'):
full_filename = os.path.join(source, files)
shutil.copy(full_filename,destination1)
elif (fileExtension=='.wav'):
full_filename = os.path.join(source, files)
shutil.copy(full_filename,destination2)
else:
print "This is not a valid file format "
错误:我一直都会出现意外缩进等错误,我不明白我在哪里犯错,而且我使用的是Python 2.7
答案 0 :(得分:1)
您需要将行fileName, fileExtension = os.path.splitext(files)
向右移动四个空格。
看看pylint。它会告诉你错误的位置。
例如,针对您的代码运行pylint
:
pylint -r n /tmp/foo
************* Module foo
E: 13,0: expected an indented block