这里是越野车part of my code:
def sort_image(path1,path2=None):
import os
import shutil
path_list=[]
if path2 is None:
for i in range(1,len(os.listdir(path1))+1):
pathh_temp = path1 + '/' + '%d_Hazy.bmp'%(i)
path_list.append(pathh_temp)
else:
list_i = os.listdir(path1)
for i in list_i:
if i.find('Imagei') != -1:
shutil.move(path1+'/'+i, path2+'/' + i)
else:
continue
for i in range(1,len(os.listdir(path2))+1):
pathi_temp = path2+ '/' + '%d_Image_.bmp'%(i)
path_list.append(pathi_temp)
return path_list
当我尝试调用该函数时,我得到this result:
File "build_data.py", line 25
path_list.append(pathh_temp)
^
IndentationError: unindent does not match any outer indentation level
当我分别在终端中运行相同的代码时,它可以正常运行。为什么?如何解决此错误?
答案 0 :(得分:0)
欢迎堆栈溢出!
第一件事,是对将要阅读您问题的人员的帮助:始终直接在问题中直接复制粘贴您的相关代码(这一次我已经为您完成了;))。
谈到您的问题,我认为您在第29行有错字:
[HttpPost]
[Route("InsertData")]
public async Task<IActionResult> InsertData([FromBody] Model model) {
try {
if(ModelState.IsValid) {
_webHookDb.UserData.Add(new UserData() {
FromAddress = model.FromAddress,
DateTime = DateTime.Now
});
await _webHookDb.SaveChangesAsync();
return new Ok(model);
}
return BadRequest(ModelState); //Bad data?
} catch (Exception ex) {
return StatusCode(500, ex.Message); //Something wrong with my code?
}
}
,末尾没有冒号“:”。
下面的代码对我有用(尽管您没有告诉您代码应该做什么:我通过阅读来猜测):
list_i = os.listdir(path1)
尝试看看是否可行!