import builtins
def open(path):
f = builtins.open(path, 'r')
return UpperCaser(f)
class UpperCaser:
'''Wrapper around a file that converts output to uppercase.'''
def __init__(self, f):
self._f = f
def read(self, count=-1):
return self._f.read(count).upper()
# ...
有個實作細節是,大多數模組都將名稱 __builtins__
作為其全域性變數的一部分以提使用。__builtins__
的值通常是這個模組或者這個模組的 __dict__
屬性值。由於這是一個實作細節,因此 Python 的其他實作可能不會使用它。
2001-2024, Python Software Foundation.
This page is licensed under the Python Software Foundation License Version 2.
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
See History and License for more information.