@Channelchan
2018-09-29T22:44:12.000000Z
字数 2517
阅读 77847
想使用Python源文件,只需在另一个源文件里执行import语句,语法如下:
import numpy
n = numpy.array([[1,2],[3,4]])
n
array([[1, 2],
[3, 4]])
import matplotlib.pyplot as plt
plt.plot(n)
plt.show()
这提供了一个简单的方法来导入一个模块中的所有项目。然而这种声明不该被过多地使用。
把一个模块的所有内容全都导入到当前的命名空间也是可行的,只需使用如下声明:
from datetime import *
time
datetime.time
Python的from语句让你从模块中导入一个指定的部分到当前命名空间中。
dir()函数一个排好序的字符串列表,返回的列表容纳了在一个模块里定义的所有模块,变量和函数。
from datetime import time
dir(time)
['__class__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__',
'dst',
'fold',
'hour',
'isoformat',
'max',
'microsecond',
'min',
'minute',
'replace',
'resolution',
'second',
'strftime',
'tzinfo',
'tzname',
'utcoffset']
help(time)
Help on class time in module datetime:
class time(builtins.object)
| time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object
|
| All arguments are optional. tzinfo may be None, or an instance of
| a tzinfo subclass. The remaining arguments may be ints.
|
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __format__(...)
| Formats self with strftime.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __new__(*args, **kwargs) from builtins.type
| Create and return a new object. See help(type) for accurate signature.
|
| __reduce__(...)
| __reduce__() -> (cls, state)
|
| __reduce_ex__(...)
| __reduce_ex__(proto) -> (cls, state)
|
| __repr__(self, /)
| Return repr(self).
|
| __str__(self, /)
| Return str(self).
|
| dst(...)
| Return self.tzinfo.dst(self).
|
| isoformat(...)
| Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
|
| timespec specifies what components of the time to include.
|
| replace(...)
| Return time with new specified fields.
|
| strftime(...)
| format -> strftime() style string.
|
| tzname(...)
| Return self.tzinfo.tzname(self).
|
| utcoffset(...)
| Return self.tzinfo.utcoffset(self).
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| fold
|
| hour
|
| microsecond
|
| minute
|
| second
|
| tzinfo
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| max = datetime.time(23, 59, 59, 999999)
|
| min = datetime.time(0, 0)
|
| resolution = datetime.timedelta(0, 0, 1)
time(23, 59, 59, 999999).microsecond
999999
time?