Nadpisywanie funkcji print w Pythonie

By Piotr Sikora

  • 6 September 2025

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()

Categories

Recent Posts

About Me

Piotr Sikora - Process Automation | AI | n8n | Python | JavaScript

Piotr Sikora

Process Automation Specialist

I implement automation that saves time and money, streamlines operations, and increases the predictability of results. Specializing in process automation, AI implementation, and workflow optimization using n8n, Python, and JavaScript.

n8n Workflows

n8n workflow automation templates

Explore my workflow templates on n8n. Ready-to-use automations for blog management, data collection, and AI-powered content processing.

3Workflow Templates

• Auto-Categorize Blog Posts with AI

• Collect LinkedIn Profiles

• Export WordPress Posts for SEO

Podobne artykuły

Odkryj więcej powiązanych treści

Implementacja szyfru XOR: Szyfrowanie w Pythonie

Implementacja szyfru XOR: Szyfrowanie w Pythonie

Poznaj implementację szyfru XOR w Pythonie. Dowiedz się jak działa ten algorytm szyfrowania z praktycznymi przykładami kodu i analizą.