python错误:TypeError: 'module' object is not callable
来源:互联网 发布:淘宝网2017女装冬装 编辑:程序博客网 时间:2024/05/17 16:55
一、调用自己写的库函数
文件:quadratic.py
import math
def quadratic(a,b,c):
x1 = float()
x2 = float()
if a == 0:
if b == 0:
if c == 0:
print('有无穷解')
else:
print('无解')
else:
x1 = -(b/c)
print('只有一个解,x1 = %.4f'%x1)
else:
det = b*b-4*a*c
if det > 0:
print('无实数解')
elif det == 0:
x1 = -(b/(2*a))
x2 = x1
print('有两个相同解,x1 = %.4f,x2 = %.4f'%(x1,x2))
else:
temp = math.sqrt(det)
x1 = (-b + temp)/(2*a)
x2 = (-b - temp)/(2*a)
print('有两个解,x1 = %.4f,x2 = %.4f'%(x1,x2))
问题:
文件:text.py
import quadratic
a = 1.0b = 2.0
c = 1.0
quadratic(a, b, c)
执行以上文件将会出现错误:TypeError: 'module' object is not callable
解决办法:
方法一:
from datetime import datetime是只引入datetime包里的datetime类,在使用时无需添加模块名的限定
查阅了之后发现需要如下写法才能运行:(from ... import ...)
from quadratic import quadratic
a = 1.0
b = 2.0
c = 1.0
quadratic(a, b, c)
方法二:
import datetime是引入整个datetime包,如果使用datetime包中的datetime类,需要加上模块名的限定
import quadratic
a = 1.0b = 2.0
c = 1.0
quadratic.quadratic(a, b, c)
二、文件命名影响调用原库函数
当文件命名为 ‘numpy.py’ 时,在文件内调用如下:
import numpy as npa = np.random.rand(10)print(a)
- python错误TypeError: 'module' object is not callable 的解决方法
- python错误TypeError: 'module' object is not callable 的解决方法
- python错误:TypeError: 'module' object is not callable
- python错误:TypeError: 'module' object is not callable
- python出现TypeError: 'module' object is not callable错误
- python TypeError: 'module' object is not callable
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- python import 包问题:TypeError: 'module' object is not callable
- 【python系列】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- Python TypeError: 'module' object is not callable 详解
- TypeError: 'module' object is not callable
- TypeError: 'module' object is not callable
- TypeError: 'module' object is not callable
- TypeError: 'module' object is not callable
- python3实战|python3爬取豆瓣top250备份到数据库
- 初学MyBatis
- getIntent().getExtras().getString()为null的问题
- HTTP和SOAP完全就是两个不同的协议
- Method createStream([class org.apache.spark.streaming.api.java.JavaStreamingContext, class java.uti
- python错误:TypeError: 'module' object is not callable
- 500 G JAVA视频网盘
- Solr-reference-About This Guide-1
- java 自定义标签JSTL
- 中间件的定义、结构
- 专业的Excel管理工具LibXL V3.8.0发布 | 附下载
- js当前光标位置分析
- springMVC框架及基本工作流程
- Go语言的匿名函数与闭包