rgfewfger

This commit is contained in:
27942
2025-12-08 16:38:40 +08:00
parent af1f98a87a
commit 3c82d117f2
2 changed files with 29 additions and 18 deletions

14
test.py
View File

@@ -6,12 +6,7 @@ class MyClass:
def start(self):
print("启动方法已执行")
def my_method(self):
print("指定的方法正在执行")
print(bfghsgrg)
# 模拟可能出现的错误
# 下面这行代码会触发一个异常,你可以根据需要注释掉它来测试正常情况
# result = 1 / 0
def end(self):
print("结束方法已执行")
@@ -22,6 +17,13 @@ class MyClass:
def __exit__(self, exc_type, exc_value, traceback):
self.end()
def my_method(self):
print("指定的方法正在执行")
print(bfghsgrg)
# 模拟可能出现的错误
# 下面这行代码会触发一个异常,你可以根据需要注释掉它来测试正常情况
# result = 1 / 0
# 使用 with 语句来调用这个类和方法
with MyClass() as obj: