Разбор строки ввода из класса в dirsync - PullRequest
0 голосов
/ 02 мая 2020

Я создаю программу для синхронизации c файлов. Пока у меня есть это, чтобы сохранить входные данные каталога в строку, но я не могу вызвать ее.

Я получаю ошибку

    sync(self.folderone[0], self.foldertwo[0],'sync',verbose=True,content=True,purge=True,create=True)
TypeError: 'method' object is not subscriptable'

Код:

# Invoke mover
from dirsync import sync
# Folder sync locations
class LOCATION():
    # Directory variables
    source_folder = []
    destination_folder = []
    parity_folders = []

    # Directory to be copied, add to list.
    def source_directory(self):
        sourcefolder = input("Select Source Directory: ")
        self.source_folder.append(sourcefolder)
    # Directory to be copied to, add to list.
    def destination_directory(self):
        destinationfolder = input("Select Destination Directory: ")
        self.destination_folder.append(destinationfolder)
    # Add both directories to a single string
    def concatenate_folders(self):
        self.parity_folders.append(LOCATION.source_folder)
        self.parity_folders.append(LOCATION.destination_folder)
    # Dump results to console
    def print_result_folders_source(self):
        print("You have selected the source directory: "+ self.source_folder[0])
    def print_result_folders_destination(self):
        print("You have selected the destination directory: "+ self.destination_folder[0])

# Location variables
folder_locations = LOCATION()
# Call class for user input on directories, then print to console.
folder_locations.source_directory()
folder_locations.print_result_folders_source()
folder_locations.destination_directory()
folder_locations.print_result_folders_destination()

class SYNC():
    # Sync variables
    folderone = folder_locations.source_directory
    foldertwo = folder_locations.destination_directory
    def user_sync(self):
#        print(folder_locations.source_directory[0,1]
        sync(self.folderone[0], self.foldertwo[0],'sync',verbose=True,content=True,purge=True,create=True)
#        sync(folder_locations.source_directory[0],folder_locations.destination_directory[0],'sync',verbose=True,content=True,purge=True,create=True)            

f_sync = SYNC()
f_sync.user_sync()

1 Ответ

0 голосов
/ 02 мая 2020

ошибка в том, что вы пытаетесь получить доступ к 0-му элементу списка в self.folderone [0], но self.folderone - это folder_locations.source_directory. Я думаю, что вы хотели написать

    folderone = folder_locations.source_folder
    foldertwo = folder_locations.destination_folder

, поскольку source_directory и destination_directory являются методами этого класса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...