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. OpenStack openvswitch 实践

    先说下我这架构就是2个节点控制节点+计算节点,网络这采用ovs方法没有路由,就是二层打通并且可以多vlan. 网络架构图: eth0网卡走trunk,走多vlan.从dashboard上创建不同的vl ...

  2. AtCoder Regular Contest 81

    链接 C.Make a Rectangle 给出一堆木棍的长度 从中选4根,询问在能围成矩形的情况下,矩形的最大面积 开个map统计一下就行 分正方形和矩形分别统计即可 复杂度$O(n \log n) ...

  3. 压测工具Siege

    一.下载 http://www.joedog.org/ http://www.joedog.org/pub/siege/siege-2.70.tar.gz 二.测试 siege -c200 -r10 ...

  4. 哈希表(散列表)—Hash表解决地址冲突 C语言实现

    哈希表(Hash table,也叫散列表),是根据关键码值(Key value)而直接进行访问的数据结构.也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度.具体的介绍网上有很详 ...

  5. 第2篇--JVM的内存区域划分

    学过C语言的朋友都知道C编译器在划分内存区域的时候经常将管理的区域划分为数据段和代码段,数据段包括堆.栈以及静态数据区.那么在Java语言当中,内存又是如何划分的呢? 由于Java程序是交由JVM执行 ...

  6. hdu 4240 最大流量路径

    题意弄了半天: 给出一个有向图,带边权,src,dst. 求出src到dst的最大流,再求出从src到dst流量最大的路径的流量,求它们的比值. #include <cstdio> #in ...

  7. php操作redis出现不报错就退出

    金乐园项目 php操作redis出现不报错就退出  死活找不出原因是因为下面这句话导致:     原因igbinary扩展没有装上 $options[\Redis::OPT_SERIALIZER] = ...

  8. [转]安卓虚拟机启动后报错: 类似 SDK Manager] Error: Error parsing .devices.xml 解决方案

    昨天用android sdk manager 更新了android sdk, 我是在myeclipse上面安装adt来开发android的现在每次打开myeclipse都报错, 而且我每次打开虚拟机的 ...

  9. 2015 UESTC 数据结构专题E题 秋实大哥与家 线段树扫描线求矩形面积交

    E - 秋实大哥与家 Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/contest/show/59 De ...

  10. JAVA容器-重点总结与深度解析

    重点内容总结 问题思考 问题思考解析