Можно ли убрать with ... as и for?
Учюсь по книге "Укус Питона" это пятая версия программы для сжатия файла и я всё ломаю голову как убрать конструкцию with ... as и циклы for. заранее спасибо за помощь
import os
import time
import zipfile
source = ['D:\\static']
target_dir = 'D:\\Backup'
today = target_dir + os.sep + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')
comment = input('Введите комментарий --> ')
if len(comment) == 0:
target = today = os.sep + now + '.zip'
else:
target = today + os.sep + now + '_' + \
comment.replace(' ','_') + '.zip'
if not os.path.exists(today):
os.mkdir(today)
print('Каталог успешно создан', today)
with zipfile.ZipFile(target, 'w', zipfile.ZIP_DEFLATED, True) as myzip:
for source_folder in source:
for root,dirs,files in os.walk(source_folder):
for file in files:
path = os.path.join(root, file)
myzip.write(path)
print(path)
print('Архивация успешна')