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

yipeiwu_com6年前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 encode和decode的妙用

>>> "hello".encode("hex") '68656c6c6f' 相应的还可以 >>> '68656c6c6f'.decode("hex"...

Python3实现简单可学习的手写体识别(实例讲解)

Python3实现简单可学习的手写体识别(实例讲解)

1.前言 版本:Python3.6.1 + PyQt5 + SQL Server 2012 以前一直觉得,机器学习、手写体识别这种程序都是很高大上很难的,直到偶然看到了这个视频,听了老师...

python通过tcp发送xml报文的方法

如下所示: # -*- coding: utf-8 -*- import socket # 使用tcp发送请求报文 def tcpsend(ip, port, xmlbw): ad...

修改Pandas的行或列的名字(重命名)

pandas.DataFrame.rename 使用函数: DataFrame.rename(mapper=None, index=None, colum...

Python中文编码那些事

首先,要明白encode()和decode()的区别  encode()的作用是将Unicode编码的字符串转换为其他编码格式。 例如: st1.encode("utf-8")...