Skip to content

Latest commit

 

History

History
41 lines (26 loc) · 1.02 KB

notes.md

File metadata and controls

41 lines (26 loc) · 1.02 KB

Rationales behind some changes:

  1. Change package names like 'naive-bayes' to valid Python identifiers. The package with invalid name can be imported only with special code like:

naive_bayes = __import__('naive-bayes')

instead of

import naive_bayes

when package name is a valid Python identifier.

  1. Pre-2.1 Python classes are not used, because they are not properly integrated into type system.

  2. EmailObject.file is removed, because it creates useless entanglement

  3. The variable name 'file' is not used because overrides the built-in function 'file'.

  4. 'file' is not closed by EmailObject, because it violates SRP (the 'file' object is owned and opened by caller).

  5. The standard Python idiom with open('name') as fp: used because it provides exceptional stability (it closes file if any exception occurs inside the block).

This

with open('name') as fp:
    do_something(fp)

is short equivalent (approximately) of:

try:
    fp = open('name')
    do_something(fp)
finally:
    fp.close()