对python模块中多个类的用法详解

春天来了,花园里开满了花,有梅花,有迎春花,有山茶花,有丁香花,真是太好看了。

如下所示:

import wuhan.wuhan11
 
class Han:
 def __init__(self, config):
  self.batch_size = config.batch_size
  self.num_steps = config.num_steps
 
class config:
 batch_size = 10
 num_steps = 50
 
if __name__ == '__main__':
 han = Han(config)
 print(han.batch_size)
 print(han.num_steps)

输出结果:

/home/ubuntu/workspace/pythondemo/env/bin/python /home/ubuntu/workspace/BioEvent/wuhan/Han.py
10
50

Process finished with exit code 0

刚学习Python,所以一点点学会的东西都想要记载怕秀逗脑袋瓜记不住:

感悟:

1. batch_size和num_steps可以理解成类Han的成员变量

2. class 类型 可以不用实例化直接作为参数使用

3. 模块中可以有多个类

以上这篇对python模块中多个类的用法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能有感兴趣的文章
Python自动化运维-使用Python脚本监控华为AR路由器关键路由变化

Python自动化运维-netmiko模块设备自动发现

Python自动化运维—netmiko模块连接并配置华为交换机

Python自动化运维-利用Python-netmiko模块备份设备配置

Python3内置模块之json编码解码方法详解