-
카테고리
-
세부 분야
프로그래밍 언어
-
해결 여부
미해결
Error발생합니다1
24.01.21 16:16 작성 조회수 109
0
file=open('./testfile1.txt','w')
try:
file.write('Context Manager Test1 \nContextlib Test1.')
finally:
file.close() #Resource Allocated and return
with open('./testfile2.txt', 'w') as f:
f.write('Context Manager Test2\nContextlib Test2.')
#EX3 Use class and Context Manager with exception Handling
#class Enter and Exit MEthod
class MyFileWriter:
def __init__(self, file_name,method):
print('MyFileWriter started : __init__')
self.file_obj=open(file_name,method)
def __enter__(self):
print("MyFileWriter started : __enter__")
return self.file_obj
def __exit__(self,exc_type,value,trace_back):
print("MyFileWriter started: __exit__")
if exc_type:
print('Logging exception {}'.format((exc_type,value,trace_back)))
self.file_obj.close()
with MyFileWriter('./testfile3.txt','w') as f:
f.write('Conetext Manager Test3\nContextlib Test3.')
답변을 작성해보세요.
0
좋은사람
지식공유자2024.01.22
안녕하세요.
현재 로그상태로는 logging exception 이네요 비밀번호나 사이트 상에 문제가 있는 것 같습니다.
좀 시간이 지난뒤에 다시 시도해보시거나, 비밀번호 등을 확인해 보시는게 좋을것 같아요!
감사합니다.
답변 1