file的doc
>>> print file.__doc__
file(name[, mode[, buffering]]) -> file object
Open a file. The mode can be 'r', 'w' or 'a' for reading (default),
writing or appending. The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing. Add a 'b' to the mode for binary files.
Add a '+' to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line buffered, and larger numbers specify the buffer size. The preferred way to open a file is with the builtin open() function.
Add a 'U' to mode to open the file for input with universal newline support. Any line ending in the input file will be seen as a '\n' in Python. Also, a file so opened gains the attribute 'newlines';
the value for this attribute is one of None (no newline read yet), '\r', '\n', '\r\n' or a tuple containing all the newline types seen.
'U' cannot be combined with 'w' or '+' mode.
open的doc
>>> print open.__doc__
open(name[, mode[, buffering]]) -> file object
Open a file using the file() type, returns a file object. This is the preferred way to open a file. See file.__doc__ for further information.
总结
- file和open都可以对文件进行操作,但是在对文件打开操作,优先使用file
Inf和NaN
Inf表示无穷大,NaN表示not a number,在运算溢出等时候可能会产生此类结果。
inf可以用 ==来比较,NaN不可以用这个来比较,两个NaN是不相等的。
>>> float("Inf") == float("Inf")
True
>>> float("Inf") == 1
False
>>> float("NaN") == float("NaN")
False
- 如何判定NaN和Inf:用isinf(),isnan()
import numpy as np
>>> a = np.arange(3,dtype
>>> a[0] = np.nan
>>> a[1] = np.inf
>>> a[2] = -np.inf
>>> a[1]
inf
>>> a[0]
nan
>>> a[2]
-inf
>>> np.isnan(a[0])
True
>>> np.isinf(a[1])
True
>>> np.isinf(a[2])
True
- 用math判断
import math
>>> math.isinf(float("inf"))
True