简体   繁体   中英

TabError: inconsistent use of tabs and spaces in indentation when adding to a dictionary

I am trying to move selected images from nested subdirectories. I am match sku from an excel file to the image name (which is also the sku number). Any that matches are then moved into a new folder.

My challenge when I try to create a dictionary to save my full directory I am being faced with the following error message.

File "c:\printing\python\data_clean.py", line 56 fullpath_filelist = {file: os.path.join(root,dirs, file} ^ TabError: inconsistent use of tabs and spaces in indentation

#! python 3
# Create clean version of data file

import openpyxl, webbrowser, sys,re, os, shutil

print('Opening workbook')

#*********************
Main_Searchterm = 'Find'
Sub_Searchterm  = 'Marine'
Data_path = 'C:\Printing\Python\data\datafile.xlsx'
Image_folder = 'C:\Printing\Python\data\images'
Sorted_folder ='C:\Printing\Python\data\sorted'
#**********************

def find_category():
    wb = openpyxl.load_workbook(Data_path)

    sheet = wb['Sheet1']


    #This looks for the main search term and put it into column 6
    for rowNum in range(2, sheet.max_row+1):
        category = sheet['E' + str(rowNum)].value  #This control which column to search from
        keywordRegex= re.compile(Main_Searchterm)
        mo = keywordRegex.search(category)
        try:
            if mo.group() == Main_Searchterm:
                sheet.cell(row = rowNum, column = 6).value = Main_Searchterm #This control which column to add the new search term
        except:
            pass

    #This looks for the sub search term and put it into column 7
    for rowNum in range(2, sheet.max_row+1):
        category = sheet['E' + str(rowNum)].value  #This control which column to search from
        keywordRegex= re.compile(Sub_Searchterm)
        mo = keywordRegex.search(category)
        try:
            if mo.group() == Sub_Searchterm:
                sheet.cell(row = rowNum, column = 7).value = Sub_Searchterm #This control which column to add the new search term
        except:
            pass


    wb.save(Data_path)

wb = openpyxl.load_workbook(Data_path)
sheet = wb['Sheet1']

filelist = [] #List of all files in directory and subdirectory
fullpath_filelist ={}
for root, dirs, files in os.walk(Image_folder):
    for file in files:
        #append the file name to the list
        filelist.append(file)
        fullpath_filelist = {file: os.path.join(root,dirs, file}

for filename in filelist:
    for rowNum in range(2, sheet.max_row+1):
    #for rowNum in range(2, 3):
        image = sheet['H' + str(rowNum)].value  #This control which column to search from
        final_path = os.path.join(root,Main_Searchterm,Sub_Searchterm,filename)

        if str(image) == str(filename):
            shutil.move(filename,final_path)

find_category()

Depending on the IDE, ctrl-F for the '\t' and replace with ' ' (4 spaces)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM