如何缩进以下打印

how to indent the following prints

假设我有其他人的功能,它执行以下操作:

def print_numbers(N):
    for i in range(N):
        print(i,'- something something')

现在 不更改函数 我想从外部调用它,这样它将打印有初始缩进(为简单起见,我们说 \t) :

Here are some random numbers:
     0 - something something
     1 - something something
     2 - something something
     3 - something something
     4 - something something

我试过这样的事情:

print('Here are some random numbers:')
with textwrap.set_indent('\t'):
    print_numbers(5)

但是我找不到这样的方法.. 可能吗?

你可以这样做:

def print_numbers(N):
    for i in range(N):
        print(i,'- something something')

def special_print(*args):
    pf('\t', *args)

pf = print # save reference to original built-in
print = special_print # override
print_numbers(5)
print = pf # reset built-in