W tym przypadku y jest puste. ( t (*args) and y (**kwargs) in Python )
[ on-line ]
import functools
def a(r):
def c(*t, **y):
with open(t[1], 'a') as file:
file.write(', '.join(f'{x}' for x in t) + '\n')
return r(*t, **y)
return c
@a
def b(a, v):
print('Plik utworzony')
# r'd:\test.txt'
print(b('zapis', r'test.txt')) # jest None bo def b nic nie zwraca (return)
Zapisał bym to tak bez przekazywania ścieżki do pliku do funkcji
[ on-line ]
import functools
def a(r):
def c(*t, **y):
# with open(r'D:\test.txt', 'a') as file:
with open('test.txt', 'a') as file:
file.write(', '.join(f'{x}' for x in t) + '\n')
return r(*t, **y)
return c
@a
def b(a):
print('Plik utworzony')
print(b('zapis')) # jest None bo "def b" nic nie zwraca (return)
[ with statement in Python ]