在使用with语句和imaplib时,必须调用close,logout

时间:2017-01-22 05:11:38

标签: python python-3.x imaplib

使用close语句时,是否有必要在logout课程上调用imap4with方法?

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
    ...

1 个答案:

答案 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>