Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added 1.txt
Empty file.
Empty file added 2.txt
Empty file.
Empty file added msg.txt
Empty file.
36 changes: 36 additions & 0 deletions program1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import time

def input_message(method_count=0):
with open('exercises/2.txt', 'w') as f:
f.write('')

with open('exercises/msg.txt', 'a') as f:
f.seek(0)
f.truncate()
while True:
method = input('Ввести метод та параметри: ')
if method == 'quit':
open('exercises/1.txt', 'w').write('quit')
quit()
if not method:
break
method_count += 1
string = f'{method}\n'
f.write(string)

with open('exercises/1.txt', 'w') as f:
f.write(str(method_count))

def execution():
input_message()
while True:
try:
with open('exercises/2.txt', 'r') as f:
s = f.read()
if s:
break
except IOError: pass
time.sleep(1)
execution()

execution()
71 changes: 71 additions & 0 deletions program2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import time

def execution_cls(cls):
error_number = 0
execution_number = 0
with open('exercises/1.txt', 'r+') as f:
if f.readline().split()[0] == 'quit':
f.truncate(0)
quit()
f.truncate(0)

with open('exercises/msg.txt') as f:
lines = f.readlines()
for line in lines:
line = line.split()
if line[0] == 'quit':
quit()
elif line[0] == 'call':
print(f'Виконання методу {line[1]}:')
try:
method = getattr(cls, line[1])
method(cls, *line[2:])
execution_number += 1
except AttributeError:
error_number += 1
print(f' Методу {line[1]} немає у класі!')
except TypeError:
error_number += 1
print(' Некоректна кількість параметрів: метод не виконано!')
elif line[0] == 'add_method':
print(f'Додавання методу {line[1]}:')
length = int(line[2])
def dynamic_method(self, *args):
if len(args) == length:
print(*args)
else:
raise TypeError
setattr(cls, line[1], dynamic_method)
print(f' Метод {line[1]} додано!')
execution_number += 1
print(f'Виконано: {execution_number}; помилок: {error_number}.')

with open('exercises/2.txt', 'w') as f:
f.write(str(execution_number+error_number))

class Recepient:

def __init__(self):
pass

def method_1(self, a):
print(a)

def method_2(self, a, b, c):
print(a, b, c)

def execution_main():
while True:
try:
with open('exercises/1.txt', 'r') as f:
s = f.read()
if s:
break
except IOError: pass
time.sleep(1)

execution_cls(Recepient)
execution_main()


execution_main()