TypeError: module() takes at most 2 arguments (3 given)
1. 错误提示
2. 代码
class Parent:
"""定义父类"""
def __init__(self):
print("调用父类构造函数")
import Parent class Child(Parent):
"""定义子类"""
def __init__(self):
print("调用子类构造方法") child = Child() # 实例化子类

3. 错误原因
此处想要导入类,如上代码所示只是导入了模块,Python的模块名与类名是在两个不同的名字空间中,初学者很容易将其弄混淆。
python 类
用来描述具有相同的属性和方法的对象的集合。它定义了该集合中每个对象所共有的属性和方法。对象是类的实例
python 模块
模块,在Python可理解为对应于一个文件。
根据上面代码,你想使用 import Parent 导入Parent 类,但 import Parent 只能导入模块,所以错误
4. 解决方法
方法一
使用正确方式导入类, import Parent from Parent (此操作就是导入Parent 模块中的 Parent 类)
方法二
修改 class Child(Parent): 代码为 class Child(Parent.Parent):,目的也是选中模块中的类
5. 正确调用的代码
方法一
from Parent import Parent class Child(Parent):
"""定义子类"""
def __init__(self):
print("调用子类构造方法") child = Child() # 实例化子类

方法二
import Parent class Child(Parent.Parent):
"""定义子类"""
def __init__(self):
print("调用子类构造方法") child = Child() # 实例化子类

转载
Python:彻底理解并解决错误TypeError: module.__init__() takes at most 2 arguments (3 given)_不懂一休-CSDN博客
TypeError: module() takes at most 2 arguments (3 given)的更多相关文章
- python3在使用类基础时,遇到错误TypeError: module.**init**() takes at most 2 arguments (3 given)
python3在使用类基础时,遇到错误TypeError: module.init() takes at most 2 arguments (3 given) 1.原因:直接导入的py文件,而没有导入 ...
- Python基础-TypeError:takes 2 positional arguments but 3 were given
Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...
- python:TypeError: main() takes 0 positional arguments but 1 was given
TypeError: main() takes 0 positional arguments but 1 was given def main(self): 括号里加上self就好了
- Python中错误之 TypeError: object() takes no parameters、TypeError: this constructor takes no arguments
TypeError: object() takes no parameters TypeError: this constructor takes no arguments 如下是学习python类时 ...
- TypeError: Restaurant() takes no arguments
1. 错误描述 TypeError: Restaurant() takes no arguments 2. 原因:在编写__init__时,pycharm会自动添加关键字,有时会直接写称整型int, ...
- TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133
程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name ...
- python3.5安装pyHook,解决【TypeError: MouseSwitch() missing 8 required positional arguments: 'msg', 'x', 'y', 'data', 'time', 'hwnd', and 'window_name'】这个错误!
为什么安装 pyHook包:为Windows中的全局鼠标和键盘事件提供回调. Python应用程序为用户输入事件注册事件处理程序,例如鼠标左键,鼠标左键,键盘键等 先要实时获取系统的鼠标位置或者键盘输 ...
- tensorflow 升级到1.9-rc0,tensorboard 报错:TypeError: GetNext() takes exactly 1 argument (2 given)
Exception in thread Reloader:Traceback (most recent call last): File "/usr/lib/python2.7/threa ...
- Python TypeError: 'module' object is not callable 原因分析
今天尝试使用pprint进行输出,语句为 >>>import pprint >>>pprint(people) 结果报错,TypeError: 'module' o ...
随机推荐
- iMX6UL配置MCP2515模块(SPI转CAN)——基于迅为iTOP-iMX6UL开发板
写在前面 在文章"嵌入式Linux的CAN总线配置--基于迅为iTOP-4412开发板"中我给4412开发板配置了SPI转CAN模块,使用的是不带设备树的内核.在本篇文章中,要 ...
- noip模拟测试50
考试过程:开题顺序1,2,3,做T1的时候我想到了要求的东西,就是分成尽量少的段使得每段之和>=k,但是我不会求,就打了个暴力走了,然后看T2,这题我觉得和之前做过的一道题比较像,因为我觉得\( ...
- Intel® QAT加速卡之同步异步模式
QAT 的两种操作模式 Intel QAT API同时支持同步和异步两种操作模式. 为了获得最佳性能,该应用程序应能够向加速引擎提交多个未完成的请求. 提交多个未完成的请求可最大程度地减少加速引擎上的 ...
- go build 与go install
相同点都能生成可执行文件 不同点go build 不能生成包文件, go install 可以生成包文件go build 生成可执行文件在当前目录下, go install 生成可执行文件在bin目录 ...
- 使用Dockerfile Maven插件
我们常见开源项目中使用的Docker Maven插件是com.spotify:docker-maven-plugin.可用版本信息见Github. 通过其介绍可知该插件已经不再推荐使用,取而代之的是c ...
- Alibaba《Java开发手册》之Java代码规范笔记
前言 一种工具被发明出来,那么针对这种工具的各种使用规则.条条框框就随之而来.无规矩不成方圆,无制度则无国家,无风格不成代码!治国有国法.排兵布阵有章法.那么写代码也有它界内通用的不成俗的约定.最近刚 ...
- 215 day01_Object类、常用API
day01[Object类.常用API] 主要内容 Object类 Date类 DateFormat类 Calendar类 System类 StringBuilder类 包装类 教学目标 -[ ] 能 ...
- CodeForce-762B USB vs. PS/2(贪心)
USB vs. PS/2 CodeForces - 762B 题意:有三种电脑,分别有a.b.c个,第一种只有USB接口,第二种只有PS/2接口,第三种有两种接口,有m个鼠标,告诉你价钱和接口类型,问 ...
- 在PHP中使用SPL库中的对象方法进行XML与数组的转换
虽说现在很多的服务提供商都会提供 JSON 接口供我们使用,但是,还是有不少的服务依然必须使用 XML 作为接口格式,这就需要我们来对 XML 格式的数据进行解析转换.而 PHP 中并没有像 json ...
- 后期静态绑定在PHP中的使用
什么叫后期静态绑定呢?其实我们在之前的文章PHP中的static中已经说过这个东西了.今天我们还是再次深入的理解一下这个概念. 首先,我们通过一段代码来引入后期静态绑定这一概念: class A { ...
