鱼C论坛

 找回密码
 立即注册
查看: 5939|回复: 1

TypeError: object of type 'int' has no len()问题

[复制链接]
发表于 2015-6-2 01:32:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
执行一个项目遇到下面错误提示:
Traceback (most recent call last):
  File "C:\Users\dahuang\Desktop\audiomapreduce-master\audiomapreduce.py", line 30, in <module>
    datasource = dict(enumerate(get_sample_data('test_data/OsBorges-EuSouComoVoceE.wav', num_of_samples=1000, skip=0)))
  File "C:\Users\dahuang\Desktop\audiomapreduce-master\audiomapreduce.py", line 13, in get_sample_data
    npts=len(num_of_samples)
TypeError: object of type 'int' has no len()

下面是主要代码:
  1. import mincemeat
  2. import wave
  3. from struct import unpack


  4. def get_sample_data(path_to_audiofile, start_pos=0, num_of_samples=44100, skip=1000):

  5.     audioData = wave.open(path_to_audiofile, 'r')
  6.     audioData.setpos(start_pos)
  7.     samples = audioData.readframes(num_of_samples)
  8.     number_of_channels = audioData.getnchannels()

  9.     npts=len(num_of_samples)
  10.     formatstr = '%ih' % (npts/2)
  11.     int_data = unpack(formatstr, samples)

  12.     format_data = []
  13.     i = 0
  14.     skip *= number_of_channels

  15.     for sample in int_data:
  16.         i += number_of_channels
  17.         if i % skip != 0:
  18.             continue
  19.         format_data.append(sample)

  20.     return format_data


  21. datasource = dict(enumerate(get_sample_data('test_data/OsBorges-EuSouComoVoceE.wav', num_of_samples=1000, skip=0)))

  22. def mapfn(k, v):
  23.     for w in v:
  24.         yield abs(w), 1


  25. def reducefn(k, vs):
  26.     result = sum(vs)
  27.     return result

  28. s = mincemeat.Server()
  29. s.datasource = datasource
  30. s.mapfn = mapfn
  31. s.reducefn = reducefn

  32. results = s.run_server(password="changeme")
  33. print results
复制代码
特来向鱼C求救...


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2015-6-2 20:48:30 | 显示全部楼层
第13行是什么意思?你想要程序如何工作?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-2-16 08:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表