当前位置:网站首页>二十五.模块/内置模块/模块的安装
二十五.模块/内置模块/模块的安装
2022-04-22 02:56:00 【随便起个名称】
一.模块
- 模块英文为Modules
- 函数与模块的关系
- 一个模块中可以包含n多个函数
- 在Python中一个扩展名为.py的文件就是一个模块
- 使用模块的好处
- 方便其他程序和脚本的导入并使用
- 避免函数名和变量名冲突
- 提高代码的可维护性
- 提高代码的可重用性
二.自定义模块
- 创建模块
- 新建一个.py文件,名称尽量不要与Python自带的标准模块名称相同
- 导入模块
- import 模块名称 [as 别名]
- 全部导入
-
import demo22 demo22.fun(demo22.Person())
- from 模块名称 import 函数/变量/类
- 部分导入
-
from demo22 import Person Person()
- import 模块名称 [as 别名]
- 可以用 dir() 查看包含了哪些可用函数
- 如果出现了导入后,显示灰色无法调用模块的情况可尝试:右键包->将目录标记为->源 根
- ##新版本pycharm自动解决了上述问题

三.内置模块
| 模块名 | 描述 |
| sys | 与Python解释器及其环境操作相关的标准库 |
| time | 提供与时间相关的各种函数的标准库 |
| os | 提供了访问操作系统服务功能的标准库 |
| calendar | 提供与日期相关的各种函数的标准库 |
| urllib | 用于读取来自网上(服务器)的数据标准库 |
| json | 用于使用json序列化和反序列化对象 |
| re | 用于在字符串中执行正则表达式匹配和替换 |
| math | 提供标准算术运算函数的标准库 |
| decimal | 用于进行精确控制运算精度、有效数位和四舍五入操作的十进制运算 |
| logging | 提供了灵活的记录事件、错误、警告和调试信息等目志信息的功能 |
| schedule | 定时运行 |
四.第三方模块的安装
- 在线安装
- 安装报错,可能是pip没设置环境变量
pip install 模块名

- 使用
import 模块名
版权声明
本文为[随便起个名称]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_55298700/article/details/124303190
边栏推荐
- Digital twin tank warfare, technology promotes battlefield information digitization
- Rational view of the advantages and disadvantages of automated testing
- How to batch modify file names and photo file names
- 循环链表的创建及可控输出
- MySQL execution process
- 收藏的技巧链接
- class数组的类似常量定义
- Pytorch image classification: the official demo of pytorch implements a classifier (lenet)
- 刷题计划——动态规划dynamic programming(二)
- 824. 山羊拉丁文(字符串分割 + 字符串替代)
猜你喜欢
![[➾ leetcode Sword means offer 12. Path in Matrix (simple)]](/img/88/2c1c7a9954d824495f0b99223ce7fc.png)
[➾ leetcode Sword means offer 12. Path in Matrix (simple)]

Why does MySQL index use B + tree instead of jump table?

Install and deploy phpstudy + DVWA vulnerability drill platform

Golang dependency injection wire. When executing the wire command, an error is reported: bash: Wire: command not found

使用 DBT-3 对 OceanBase 和 MariaDB 进行性能测试对比

Flink 细粒度资源管理新特性解读

刷题计划——动态规划dynamic programming(二)

golang依赖注入wire使用 执行wire命令时报错:bash: wire: command not found

72. Edit distance

Day12 job
随机推荐
Troubleshooting kubernetes - 10s delay
Performance test and comparison of oceanbase and MariaDB using dbt-3
Another perspective on the meta universe: the meta universe culture is quietly changing the world
Training set: alexnet classification
Verse protocol: a wonderful idea to optimize NFT liquidity
Install and deploy phpstudy + DVWA vulnerability drill platform
二叉排序树基本性质详解
Financial information security training - 22 / 4 / 19 (Part I)
The traffic lights made by enumeration have an interface
How long can we rely on play to earn economic profits?
UE4 obtains the complete map path according to the map name
Nocalhost for dapr remote debugging
Digital twin tank warfare, technology promotes battlefield information digitization
Web网站访问响应慢可能的原因
Delphi automatically adapts to the screen size
Create a two-way linked list (detailed explanation)
Mongodb grouping query
Why is the country established
When encountering a strange problem, start both local and remote transactions at the same time. The remote transaction is SQL2000. It is sql2008. No error is reported, but the data cannot be written
Complete solution of closure operation in Discrete Mathematics