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

yipeiwu_com5年前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设计】。

相关文章

Jupyter中直接显示Matplotlib的图形方法

Jupyter中直接显示Matplotlib的图形方法

一.使用以下cmd命令生成ipython_config.py 文件 ipython profile create 二.在ipython_config.py中添加以下代码 c....

python将字符串list写入excel和txt的实例

python将字符串list写入excel和txt的实例

docs = [‘icassp improved human face identification using frequency domain representation faci...

Python实现删除当前目录下除当前脚本以外的文件和文件夹实例

本文实例讲述了Python实现删除当前目录下除当前脚本以外的文件和文件夹。分享给大家供大家参考。具体如下: import os,sys import shutil cur_file...

numpy中loadtxt 的用法详解

numpy中有两个函数可以用来读取文件,主要是txt文件, 下面主要来介绍这两个函数的用法 第一个是loadtxt, 其一般用法为 numpy.loadtxt(fname, dtype=...

python实现通过pil模块对图片格式进行转换的方法

本文实例讲述了python实现通过pil模块对图片格式进行转换的方法。分享给大家供大家参考。具体分析如下: python的pil模块相当的智能,如果你需要对图片格式进行转换,比如jpg转...