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. Kubernetes-Pod介绍(-)

    前言 本篇是Kubernetes第四篇,大家一定要把环境搭建起来,看是解决不了问题的,必须实战.从现在开始都是重要的核心概念,此篇偏一些Pod的概念介绍,后续每篇都会有实战. Kubernetes系列 ...

  2. java基础之ThreadLocal

    早在JDK 1.2的版本中就提供java.lang.ThreadLocal,ThreadLocal为解决多线程程序的并发问题提供了一种新的思路.使用这个工具类可以很简洁地编写出优美的多线程程序.Thr ...

  3. Appium问题解决方案(7)- Could not find 'adb.exe' in PATH. Please set the ANDROID_HOME environment variable with the Android SDK root directory path

    背景:运行代码提示找不到ADB An unknown server-side error occurred while processing the command. Original error: ...

  4. 快速模式第一包: quick_outI1()

    文章目录 1. 序言 2. quick_outI1()流程图 3. quick_outI1()源码分析 4. quick_outI1_continue()源码分析 5. quick_outI1_tai ...

  5. jdbc核心技术-宋红康

    视频地址 JDBC核心技术 第1章:JDBC概述 1.1 数据的持久化 持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用.大多数情况下,特别是企业级应用,数据持久化意味着将 ...

  6. 干货!基于SpringBoot的RabbitMQ多种模式队列实战

    目录 环境准备 安装RabbitMQ 依赖 连接配置 五种队列模式实现 1 点对点的队列 2 工作队列模式Work Queue 3 路由模式Routing 4 发布/订阅模式Publish/Subsc ...

  7. 可选链运算符、空值合并运算符 --应用到vue项目

    1.npm安装 npm install @babel/plugin-proposal-optional-chaining // 可选链运算符 ?. npm install @babel/plugin- ...

  8. 手把手教你 Docker Compose安装DOClever

    一.什么是Docker Compose以及Docker Compose的安装和使用 查看我的另外一篇博客:Docker Compose的安装和使用 二.DOClever是什么 DOClever是一个可 ...

  9. HCNP Routing&Switching之路由策略工具Route-Policy

    前文我们了解了路由过滤和路由过滤工具Filter-Policy使用相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/15316188.html:今天我们来 ...

  10. PHP大文件读取操作

    简单的文件读取,一般我们会使用 file_get_contents() 这类方式来直接获取文件的内容.不过这种函数有个严重的问题是它会把文件一次性地加载到内存中,也就是说,它会受到内存的限制.因此,加 ...