python import 错误 TypeError: 'module' object is not callable

在这里,有 Person.py test.py; 在 test.py 里面 import Person 总是调用方法出错

Person.py

class Person:
def __init__(self,name):
self.name = name
print('this name is ',name)
def hello(self):
print('hello python')

出现错误的 test.py

import Person

person = Person('dd')
person.hello()

错误原因:原来是 import Person 表示的是 导入 Person文件里面的所有东西,调用方法,还要继续再加一层 比如,Person.Person('kk')

解决方案一:

import Person

person = Person.Person('Tom')
person.hello()

解决方案二:

from Person import *

person = Person('Tom')
person.hello()

打印结果都是:

this name is  Tom
hello python

参考:http://blog.csdn.net/huzhenwei/article/details/2895909

python import 错误 TypeError: 'module' object is not callable的更多相关文章

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

    程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name self.Sex = sex def ToS ...

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

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

  3. python -- TypeError: 'module' object is not callable

    文件: 代码: import pprintmessge = 'It was a bringht cold day in April,and the clocks were striking thrir ...

  4. PyCharm+selenium环境搭建报错:Traceback (most recent call last): TypeError: 'module' object is not callable

    环境搭建好后,代码如下: from selenium import webdriverdriver = webdriver.chrome()driver.get("http://www.ba ...

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

  6. pip安装pillow——死循环:[WinError5] & [TypeError:'module' object is not callable]

    1.这次本来要安装个pillow,记得以前装了的,怎么这次就不行了.然后,下意识的使用:pip3 install pillow. 发现报错: [TypeError:'module' object is ...

  7. pip install 报错 TypeError: 'module' object is not callable

    $ pip install filetype Traceback (most recent call last): File "/usr/local/bin/pip2", line ...

  8. 解决Flask和Django的错误“TypeError: 'bool' object is not callable”

    跟着欢迎进入Flask大型教程项目!的教程学习Flask,到了重构用户模型的时候,运行脚本后报错: TypeError: 'bool' object is not callable 这是用户模型: c ...

  9. java/javac命令行如何同时引用多个包;错误 TypeError: 'JavaPackage' object is not callable 的含义

    出现这类错误提示:'JavaPackage' object is not callable,可以看下所引用的jar包或者class文件是否在java的路径搜索范围内 命令行模式下:javac可以编译* ...

随机推荐

  1. FastReport.Net使用:[27]样式使用

    样式设置与使用 1.打开样式设置界面,通过 报表->样式 来打开. 2.样式设置包含:边框,填充,字体和文本颜色.假如不需要某项设置,可将其选择框去掉. 3.设置好样式后,将标题的style设置 ...

  2. 【BZOJ 4103】 4103: [Thu Summer Camp 2015]异或运算 (可持久化Trie)

    4103: [Thu Summer Camp 2015]异或运算 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 474  Solved: 258 De ...

  3. 多个Fragment在屏幕翻转会重影问题的解决

    fragment使用add和hide而不用replace的方法添加到activity中,如果屏幕翻转可能会又add新的fragment进去,所以会重影. 如果有一个sparsearray保存fragm ...

  4. Map按照数值进行排序

    public static Map<String, Integer> sortMapByValue(Map<String, Integer> oriMap) { if (ori ...

  5. bzoj 2152

    /************************************************************** Problem: 2152 User: idy002 Language: ...

  6. python开发_bisect

    现在有如下的需求: ''' 实现这样的一个功能: 对一个班级的学生的成绩做出一些评定,评定规则是: one: [0-60) -- F two: [60-70) -- D three: [70-80) ...

  7. wampserver3.1.0安装及配置

    安装篇 环境:win10 64位+wamp3.1.0 为什么安装wamp3.1.0呢?php7早已正式发布了,还没有尝过鲜呢.点击进入wampserver下载地址 本以为下载后,执行exe文件,点ne ...

  8. Android ButterKnife注解框架使用

    这段时间学习了下ButterKnife注解框架,学习的不是特别深入,但是基础也差不多了,在此记录总结一下. ButterKnife是一个Android View注入的库,主要是注解的使用,可以减少很多 ...

  9. Windows Embedded Compact 7网络编程概述(下)

    11.1.1 Select I/O模型 在Windows CE中,Select模型是唯一被支持的I/O模型.Select I/O模型就是利用select函数对I/O进行管理. 函数select的功能在 ...

  10. [SQL基础]入门

    目录 什么是SQL? SQL能做什么? RDBMS SQL常见数据类型 SQL语法 什么是SQL? 结构化查询语言(Structured Query Language)简称SQL. 结构化查询语言是一 ...