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. 洛谷 P1115 最大子段和

    P1115 最大子段和 题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 输入文件maxsum1.in的第一行是一个正整数N,表示了序列的长度. 第2行包含N ...

  2. poj 1485 dp

    转自:http://www.cnblogs.com/kuangbin/archive/2011/11/12/2246407.html [题目大意] 一条公路上有n个旅馆,选出其中k个设置仓库,一个仓库 ...

  3. [bzoj1021][SHOI2008]Debt 循环的债务 (动态规划)

    Description Alice. Bob和Cynthia总是为他们之间混乱的债务而烦恼,终于有一天,他们决定坐下来一起解决这个问题.不过,鉴别钞票的真伪是一件很麻烦的事情,于是他 们决定要在清还债 ...

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

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

  5. 打开/查找xcode6的沙盒地目录

    用以下代码 打开沙盒目录 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainM ...

  6. 直接拿来用!最火的iOS开源项目(一~三)

    结束了GitHub平台上“最受欢迎的Android开源项目”系列盘点之后,我们正式迎来了“GitHub上最受欢迎的iOS开源项目”系列盘点.今天,我们将介绍20个在GitHub上非常受开发者欢迎的iO ...

  7. Upgrading Directly from MySQL 5.0 to 5.7 using an ‘In Place’ Upgrade

    http://mysqlserverteam.com/upgrading-directly-from-mysql-5-0-to-5-7-using-an-in-place-upgrade/

  8. Windows平台下如何使用Android NDK

    鉴于有些同学想要学习NDK,但在网上很难找到一个讲解比较清楚.按照步骤操作可以比较顺利学会NDK的文章,所以写了此篇教程. 一.学习本篇教程需要具备的条件: 1. 了解JAVA中JNI的概念.好处以及 ...

  9. 静态资源(StaticResource)和动态资源(DynamicResource)

    静态资源(StaticResource)和动态资源(DynamicResource) 资源可以作为静态资源或动态资源进行引用.这是通过使用 StaticResource 标记扩展或 DynamicRe ...

  10. RapidSVN的使用

    RapidSVN是一个可视化 SVN 客户端,运行速度快,简单易用,现在很多已经做成做成便携版,安装都不用.小乌龟那个SVN感觉太复杂了...不妨试下这个. 1.下载安装 2.运行RapidSVNPo ...