免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 24465 | 回复: 1
打印 上一主题 下一主题

总是提示:TypeError: 'module' object is not callable,请帮忙看下 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-09-28 12:29 |只看该作者 |倒序浏览
将数据进行清理并输出时,总是提示:TypeError: 'module' object is not callable,我也仔细检查了代码,没有发现什么异常,向高手们求助,我正在学习Python中,问题应该很简单,只是我是新手,可能还找不到解决的方法。

我的Python代码:
  1. with open('james.txt') as jaf:
  2.     data=jaf.readline()
  3.     james=data.strip().split(',')
  4. with open('julie.txt') as juf:
  5.     data=juf.readline()
  6.     julie=data.strip().split(',')
  7. with open('mikey.txt') as mif:
  8.     data=mif.readline()
  9.     mikey=data.strip().split(',')
  10. with open('sarah.txt') as saf:
  11.     data=saf.readline()
  12.     sarah=data.strip().split(',')

  13. clean_james = []
  14. clean_julie = []
  15. clean_mikey = []
  16. clean_sarah = []

  17. import sanitize

  18. for each_t in james:
  19.     clean_james.append(sanitize(each_t))
  20. for each_t in julie:
  21.     clean_julie.append(sanitize(each_t))
  22. for each_t in mikey:
  23.     clean_mikey.append(sanitize(each_t))
  24. for each_t in sarah:
  25.     clean_sarah.append(sanitize(each_t))

  26.     print(sorted(james))
  27.     print(sorted(julie))
  28.     print(sorted(mikey))
  29.     print(sorted(sarah))
复制代码
sanitize函数代码:
  1. def sanitize(time_string):
  2.     if '-' in time_string:
  3.         splitter = '-'
  4.     elif ':' in time_string:
  5.         splitter = '-'
  6.     else:
  7.         return(time_srting)
  8.     (mins,secs) = time_string.split(splitter)
  9.     return(mins + '.' + secs)
复制代码
提示的错误:

Traceback (most recent call last):
  File "E:\chapter5\chapter-02.py", line 22, in <module>
    clean_james.append(sanitize(each_t))
TypeError: 'module' object is not callable


下面的链接是我的代码文件和用到的文本文件:

http://www.kuaipan.cn/file/id_7230306859904272.htm

论坛徽章:
0
2 [报告]
发表于 2012-09-28 15:31 |只看该作者
你的模块名和函数名一样了,第22行解析的是你的模块名,不是函数名。

两种改法:
1, 把19行改为“from sinitize import sinitize"
2, 把22行中"sinitize"改为”sinitize.sinitize"
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP