cmd导入python模块_Python模块导入

Python模块导入

import

想使用Python源文件,只需在另一个源文件里执行import语句,语法如下:

importnumpy

n=numpy.array([[1,2],[3,4]])

print(n)[[1 2]

[3 4]]

importmatplotlib.pyplotasplt

plt.plot(n)

plt.show()

from...import*

这提供了一个简单的方法来导入一个模块中的所有项目。然而这种声明不该被过多地使用。

把一个模块的所有内容全都导入到当前的命名空间也是可行的,只需使用如下声明:

fromdatetimeimport*

from...import语句:

Python的from语句让你从模块中导入一个指定的部分到当前命名空间中。

dir()函数一个排好序的字符串列表,返回的列表容纳了在一个模块里定义的所有模块,变量和函数。

fromdatetimeimporttime

print(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']

print(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

|

| __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)

None

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值