Вы можете создать список и затем сохранить ваши объекты там:
Ниже приведен код:
#Define class in file named MediaFile.py
class MediaFile:
def __init__(self, file_name, file_path, file_type, file_comment=None, categorys=None, playlists=None):
self.file_name = file_name
self.file_path = file_path
self.file_type = file_type
self.file_comment = file_comment
self.categorys = categorys
self.playlists = playlists
# New file which contains actual code:
from MediaFile import MediaFile
import os.path
filenames = []
filepaths = []
fileextentions = []
# empty list to store objects
media_list=[]
d = input('Enter a path to organise: ')
for path in os.listdir(d):
full_path = os.path.join(d, path)
i=0
if os.path.isfile(full_path):
filepath = full_path
name = os.path.splitext(os.path.basename(full_path))[0]
extention = os.path.splitext(full_path)[1]
i+=1
# append the objects to a list
media_list.append(MediaFile(name, filepath, extention))