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)的更多相关文章

  1. python3在使用类基础时,遇到错误TypeError: module.**init**() takes at most 2 arguments (3 given)

    python3在使用类基础时,遇到错误TypeError: module.init() takes at most 2 arguments (3 given) 1.原因:直接导入的py文件,而没有导入 ...

  2. Python基础-TypeError:takes 2 positional arguments but 3 were given

    Error: 今天写一段简单类定义python代码所遇到报错问题:TypeError: drive() takes 2 positional arguments but 3 were given 代码 ...

  3. 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就好了

  4. Python中错误之 TypeError: object() takes no parameters、TypeError: this constructor takes no arguments

    TypeError: object() takes no parameters TypeError: this constructor takes no arguments 如下是学习python类时 ...

  5. TypeError: Restaurant() takes no arguments

    1. 错误描述 TypeError: Restaurant() takes no arguments 2. 原因:在编写__init__时,pycharm会自动添加关键字,有时会直接写称整型int, ...

  6. 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   ...

  7. python3.5安装pyHook,解决【TypeError: MouseSwitch() missing 8 required positional arguments: 'msg', 'x', 'y', 'data', 'time', 'hwnd', and 'window_name'】这个错误!

    为什么安装 pyHook包:为Windows中的全局鼠标和键盘事件提供回调. Python应用程序为用户输入事件注册事件处理程序,例如鼠标左键,鼠标左键,键盘键等 先要实时获取系统的鼠标位置或者键盘输 ...

  8. 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 ...

  9. Python TypeError: 'module' object is not callable 原因分析

    今天尝试使用pprint进行输出,语句为 >>>import pprint >>>pprint(people) 结果报错,TypeError: 'module' o ...

随机推荐

  1. [bug]spring项目通过反射测试私有方法时,注入对象异常

    背景 遇到问题:在进行Spring单元测试编写时,发现被测方法是一个私有方法,无法直接通过注入对象调用 解决思路:首先想到通过反射获取该私有方法的访问权限,并传入注入对象,最终调用对象的私有方法. 出 ...

  2. 分布式ID生成器及redis,etcd分布式锁

    分布式id生成器 有时我们需要能够生成类似MySQL自增ID这样不断增大,同时又不会重复的id.以支持业务中的高并发场景.比较典型的,电商促销时,短时间内会有大量的订单涌入到系统,比如每秒10w+.明 ...

  3. vue + WangEnduit

    components 注册组件 <template lang="html"> <div class="editor"> <div ...

  4. MySQL实战45讲(10--15)-笔记

    11 | 怎么给字符串字段加索引? 维护一个支持邮箱登录的系统,用户表是这么定义的: mysql> create table SUser( ID bigint unsigned primary ...

  5. shp平滑处理

    在做图像数据处理时,经常会有栅格数据转矢量数据的操作,转换后的矢量文件会存在锯齿状边缘,不太美观,因此常常需要对矢量(shp)文件做平滑处理. 1 利用arcgis实现shp的平滑和简化 ArcToo ...

  6. 20210813 a,b,c

    考场 稍微想了想发现 T1 是 sb 题,枚举矩形的三个边界,右边界双指针扫就行了,T2 八成 DP,T3 感觉非常不可做 T1 犹豫了一下要不要算补集,感觉直接写也不难,就打消了这个念头 T2 只会 ...

  7. 异步处理方式之信号(一):基础知识和signal函数说明

    文章目录 1. 引言 2. 信号的概念 2.1 信号操作之忽略信号 2.2 信号操作之捕捉信号 2.3 信号操作之执行系统默认操作 2.4 常见的信号 3. 函数signal 3.1 signal函数 ...

  8. TCP超时重传、序列号、滑动窗口简介

    文章目录 12 TCP:传输控制协议(初步) 12.1 引言 12.1.1 ARQ和重传 12.1.2 分组窗口和滑动窗口 12.1.3 变量窗口:流量控制和拥塞控制 12.1.4 变量窗口:设置重传 ...

  9. 真香!原来 CLI 开发可以这么简单

    CLI(命令行工具,Command Line Interface)大家都非常熟悉了,比如 create-react-app 等.我们今天介绍一个 CLI 工具的开发框架,可以帮助我们快速构建 CLI ...

  10. 求 10000 以内 n 的阶乘

    求 10000以内 n 的阶乘. 输入格式 只有一行输入,整数 n(0≤n≤10000) 输出格式 一行,即 n!的值. 输出时每行末尾的多余空格,不影响答案正确性 样例输入 100 样例输出 933 ...