我正在尝试使用wave模块来读取python中的wav文件。
我的应用程序不常见的是我没有使用文件或文件名来读取wav文件,而是将wav文件放在缓冲区中。
这就是我在做什么
import StringIO
buffer = StringIO.StringIO()
buffer.output(wav_buffer)
file = wave.open(buffer, 'r')
Run Code Online (Sandbox Code Playgroud)
但是我EOFError运行它时得到了...
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 493, in open
return Wave_read(f)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 163, in __init__
self.initfp(f)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 128, in initfp
self._file = Chunk(file, bigendian = 0)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/chunk.py", line 63, in __init__
raise EOFError
Run Code Online (Sandbox Code Playgroud)
我知道这些StringIO东西可以用于创建wav文件,并且我尝试了以下操作,并且效果很好
import StringIO
buffer = StringIO.StringIO()
audio_out = wave.open(buffer, 'w')
audio_out.setframerate(m.getRate())
audio_out.setsampwidth(2)
audio_out.setcomptype('NONE', 'not compressed')
audio_out.setnchannels(1)
audio_out.writeframes(raw_audio)
audio_out.close()
buffer.flush()
# these lines do …Run Code Online (Sandbox Code Playgroud) 我是铁杆的新手,这似乎很明显,但找不到答案.
当我做
u = User.where("email=?", email_string)
u.name = "new name"
Run Code Online (Sandbox Code Playgroud)
我不断工作不起作用
NoMethodError: undefined method `name=' for #<ActiveRecord::Relation:0x1049c2890>
Run Code Online (Sandbox Code Playgroud)
但如果我改变
u = User.where("email=?", email_string)
Run Code Online (Sandbox Code Playgroud)
至
u = User.find_by_email(email_string)
Run Code Online (Sandbox Code Playgroud)
我可以看到我的更改被持久化并且没有抛出任何错误.
所以我错过了什么.是吗.where返回一个只读对象或什么?