Czy wiedziałeś, że możesz łatwo nadpisać funkcję print używając FunctType? Użyj poniższego kodu, aby zobaczyć jak to działa.
import random
def random_str():
return random.choice([
'first', 'second', 'third'
])
def alt_print(s):
output = []
for ch in s:
c = ord(ch)
if c in range(ord('a'), ord('z')+1):
c += 119945
elif ord('A') <= c <= ord('Z'):
c += 119951
output.append(chr(c))
output.append(' ')
print(''.join(output))
def firstFunction(s="test"):
print(s)
import types
myFirstFunction = types.FunctionType(
firstFunction.__code__,
{
"print": alt_print
},
name="myFirstFunction",
argdefs=("Function",) # <= tutaj jest "," na końcu - TO MUSI TAM BYĆ
)
myFirstFunction()






