python import 错误 TypeError: 'module' object is not callable
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的更多相关文章
- TypeError: 'module' object is not callable 原因分析
程序代码 class Person: #constructor def __init__(self,name,sex): self.Name = name self.Sex = sex def ToS ...
- Python TypeError: 'module' object is not callable 原因分析
今天尝试使用pprint进行输出,语句为 >>>import pprint >>>pprint(people) 结果报错,TypeError: 'module' o ...
- python -- TypeError: 'module' object is not callable
文件: 代码: import pprintmessge = 'It was a bringht cold day in April,and the clocks were striking thrir ...
- PyCharm+selenium环境搭建报错:Traceback (most recent call last): TypeError: 'module' object is not callable
环境搭建好后,代码如下: from selenium import webdriverdriver = webdriver.chrome()driver.get("http://www.ba ...
- 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 ...
- pip安装pillow——死循环:[WinError5] & [TypeError:'module' object is not callable]
1.这次本来要安装个pillow,记得以前装了的,怎么这次就不行了.然后,下意识的使用:pip3 install pillow. 发现报错: [TypeError:'module' object is ...
- pip install 报错 TypeError: 'module' object is not callable
$ pip install filetype Traceback (most recent call last): File "/usr/local/bin/pip2", line ...
- 解决Flask和Django的错误“TypeError: 'bool' object is not callable”
跟着欢迎进入Flask大型教程项目!的教程学习Flask,到了重构用户模型的时候,运行脚本后报错: TypeError: 'bool' object is not callable 这是用户模型: c ...
- java/javac命令行如何同时引用多个包;错误 TypeError: 'JavaPackage' object is not callable 的含义
出现这类错误提示:'JavaPackage' object is not callable,可以看下所引用的jar包或者class文件是否在java的路径搜索范围内 命令行模式下:javac可以编译* ...
随机推荐
- [BZOJ4237]稻草人(CDQ分治)
先按y排序,二分,两边递归下去,然后处理下半部分对上半部分的贡献,即左下点在下半部分,右上点在上半部分的合法矩形个数. 两个部分均按x排序,枚举右上点p,则左下点需要满足: 1.横坐标大于上半部分纵坐 ...
- BZOJ3238 [Ahoi2013]差异 SA+单调栈
题面 戳这里 题解 考虑把要求的那个东西拆开算,前面一个东西像想怎么算怎么算,后面那个东西在建出\(height\)数组后相当于是求所有区间\(min\)的和*2,单调栈维护一波即可. #includ ...
- 【最大化平均值】POJ3111-K Best
[题目大意] 给出v[]和w[],求的最大值. [思路] 二分s(S)的值,可变形为s(S)*Σw>=Σv,所以只需要把求出x*w[i]-v[i],看看前k个的和是否大于等于0,大于等于0就满足 ...
- uoj386 【UNR #3】鸽子固定器
link (似乎很久没写题解了) 题意: n个物品,每个物品有a,b两个值,给定A,B,现在最多选其中m个,要求最大化选出的物品中[b权值和的B次方-a极差的A次方]. $n\leq 2\times ...
- Problem C: 深入浅出学算法004-求多个数的最小公倍数
Description 求n个整数的最小公倍数 Input 多组测试数据,先输入整数T表示组数 然后每行先输入1个整数n,后面输入n个整数k1 k2...kn Output 求k1 k2 ...kn的 ...
- poj 2001 trie
第一道trie 还需要写题来建立自己的代码习惯. #include <cstdio> #include <vector> #include <algorithm> ...
- hihocoder1310 岛屿
hihocoder1310 岛屿 题意: 中文题意 思路: dfs,面积和数量都很好求,问题在岛屿形状上,感觉让人比较麻烦,用vector保存各个点,只要两个岛之间每个点距离一样就好了,这里的形状的定 ...
- PHP 日期的加减
- C#获取picturebox图片路径
path = ofd.FileName; filename = ofd.SafeFileName; lu="E:\\鹿瑶\\Csharp\\DB学生报名系统\\baomingDemo\\bi ...
- 王者参考jar包