Неверный путь к файлу или тип буфера:при попытке перебрать файлы - PullRequest
0 голосов
/ 18 марта 2019

У меня обновлен код ниже;чтобы мой сценарий мог проходить по нескольким файлам в каталоге (в отличие от одного):

@classmethod
def find_file(cls):
     all_files = list()
     """"Finds the excel file to process"""
     archive = ZipFile(config.FILE_LOCATION)
     for file in archive.filelist:
        if file.filename.__contains__('Horrible Data Site '):
             all_files.append(archive.extract(file.filename, config.UNZIP_LOCATION))
     return all_files   

Перед объявлением "all files = list()" в моем методе find_files это работало на один файл в каталоге.Я добавил all_files в попытке разрешить цикл по всем файлам в каталоге.

Кроме того, в приведенном ниже main.py я только что добавил for прямо перед PENDING_RECORDS для этой цели.

"""Start Point"""

from data.find_pending_records import FindPendingRecords
from vital.vital_entry import VitalEntry
from time import sleep

if __name__ == "__main__":
    try: 
        for PENDING_RECORDS in FindPendingRecords().get_excel_data():
            # Do operations on PENDING_RECORDS

            # Reads excel to map data from excel to vital
            MAP_DATA = FindPendingRecords().get_mapping_data()

            # Configures Driver
            VITAL_ENTRY = VitalEntry()

            # Start chrome and navigate to vital website
            VITAL_ENTRY.instantiate_chrome()

            # Begin processing Records
            VITAL_ENTRY.process_records(PENDING_RECORDS, MAP_DATA)

            print (PENDING_RECORDS)
            print("All done")     
    except Exception as exc:
        print(exc)

Добавление добавления all_files() и for теперь выводит следующую ошибку в приглашении Anaconda:

(base) C:\Python>python main.py
Invalid file path or buffer object type: <class 'list'>

это config.py

FILE_LOCATION = r"C:\Zip\DATA Docs.zip"
UNZIP_LOCATION = r"C:\Zip\Pending"
VITAL_URL = 'http://horriblewebsite:8080/START'
HEADLESS = False
PROCESSORS = 4
MAPPING_DOC = ".//map/mappingDOC.xlsx"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...