import os
def catalog_search(path_to_catalog: str) -> list:
fl_lst = []
directory_ = os.walk(path_to_catalog, topdown=True)
for address, dirs, files in directory_:
for name in files:
fl_lst.append(os.path.join(address, name))
return fl_lst
def amount_file_string(string_: str) -> int:
for i_file in string_:
try:
with open(i_file, 'r') as f:
amount = f.readlines()
yield len(amount)
except FileNotFoundError:
print(f'Файл не найден: {i_file}')
catalog = 'L:\\28.Python\\Python_Basic\\Module14'
file_list = catalog_search(catalog)
file_strings = (amount_file_string(file) for file in file_list)
print(f'Найдено {len(file_list)} файлов в каталоге {catalog}.')
for i_value in file_strings:
try:
print(f'Количество строк в файле {i_value}')
except StopIteration:
pass
import time
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path == 'L:\\file_dir\\file.txt':
print(event.src_path)
if __name__ == "__main__":
event_handler = MyHandler()
observer = Observer()
observer.schedule(event_handler, path='L:\\file_dir', recursive=False)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
observer.schedule(event_handler, path='.', recursive=False)
class MyHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path == 'file.txt':
print("Файл file.txt был изменен!")
driver.find_elements(by='CLASSNAME', 'class-name')
def number_count(string):
count = 0
for ch in string:
if ch.isdigit():
count += 1
return count
alphabet = ''.join([chr(i) for i in range(ord('А'), ord('Я') + 1)] + \
[chr(i) for i in range(ord('а'), ord('я') + 1)])
while 1:
ru_count = 0
password = input('Придумайте пароль: ')
for chr in password:
for smb in alphabet:
if smb == chr:
ru_count += 1
if ru_count > 0:
print('Допускается ввод только латинских букв')
else:
if number_count(password) < 3 or password.islower() == 0 or len(password) < 8 or password.isdigit() == 1:
print('Пароль ненадёжный. Попробуйте ещё раз.')
else:
print('Пароль надёжный.')
break
def number_count(string):
count = 0
for ch in string:
if ch.isdigit():
count += 1
return count
alphabet = ''.join([chr(i) for i in range(ord('А'), ord('Я') + 1)] + \
[chr(i) for i in range(ord('а'), ord('я') + 1)])
while 1:
password = input('Придумайте пароль: ')
ru_count = 0
for chr in password:
for smb in alphabet:
if smb == chr:
ru_count += 1
if ru_count > 0:
print('Допускается ввод только латинских букв')
else:
if len(password) < 8 or number_count(password) < 3 or password.islower() == 1:
print('Пароль ненадёжный. Попробуйте ещё раз.')
else:
print('Пароль надёжный.')
break