Ответ:
--- Python 3.8.3 ---
#1 - file mdir.py
import os
import sys
import difflib
__all__ = ['CreateEmptyDir', 'RmDir']
__here__ = os.path.dirname(os.path.realpath(__file__))
#Функция, создающая папки
def CreateEmptyDir(count, path = __here__):
try:
for i in range(count):
rpath = path + f'\\dir_{i}'
os.mkdir(rpath)
except OSError:
print(f'Failed to create directory {path}')
#Функция, удаляющая папки
def RmDir(mask, path = __here__):
try:
for folder in os.listdir(path):
s = difflib.SequenceMatcher(None, mask, folder)
if s.ratio() > 0.8:
f = path + '\\' + folder
if os.path.isdir(f):
os.rmdir(f)
except OSError as e:
print(f'Failed to remove directory {f}\n{e}')
#Вызов функций из модуля
def main():
CreateEmptyDir(10)
next = input()
RmDir('dir_')
if __name__ == "__main__":
main()
#2 - file randchoise.py
import random
__all__ = ['RandChoise']
def RandChoise(lst):
if len(lst) == 0: return None
return random.choice(lst)
def main():
data = [1,2,3,4]
print(RandChoise(data))
if __name__ == "__main__":
main()
#3 main.py
from mdir import *
from randchoise import *
import time
def main():
CreateEmptyDir(10)
time.sleep(3) #Что бы успели прогрузиться созданные папки
RmDir('dir_')
print(RandChoise([1,2,3,4,5,6,7,8,9,2,1,32,31,2540]))
if __name__ == "__main__":
main()