使用close
语句时,是否有必要在logout
课程上调用imap4
和with
方法?
docs没有提供更多背景信息。
在版本3.5中更改:添加了对with语句的支持。
另一方面,非with
example,他们称之为两种方法。
这样做吗?
with imaplib.IMAP4_SSL(IMAP) as imap:
# Do some stuff
...
imap.close()
imap.logout()
或者只是这个?
with imaplib.IMAP4_SSL(IMAP) as imap:
# Do some stuff
...
答案 0 :(得分:2)
logout
来电def __exit__(self, *args): # from imaplib.py
try:
self.logout()
except OSError:
pass
:
with
所以你只需要调用close(在with imaplib.IMAP4_SSL(IMAP) as imap:
# Do some stuff
imap.close()
块之外):
<form action="Post" method="post" >
<label for="semester">Semester</label>
<input type="text" name="semester" placeholder="Enter the semester">
<label for="prof-name">Instructor's name</label>
<input type="text" name="prof-name" placeholder="Enter the instructor's name">
<label id="course-eval">How was the course?</label>
<textarea name="course-evaluation" placeholder="Write everything about the course"></textarea>
<label for="prof-eval">How was your professor?</label>
<textarea name="prof-evaluation" placeholder="Write everything about your professor"></textarea>
<input type="submit" value="Submit" >
</form>