-1
私はPythonに慣れていますが、他の言語では熟練した獣医ですが、なぜdata.dtypeがエラーAttributeError: 'tuple' object has no attribute 'dtype'
を投げ、dtype値を得ることができますか?AttributeError: 'tuple'オブジェクトに 'dtype'属性がありません
私はちょうどdata.dtype
コード
import pyaudio
import sys
import numpy
import scipy.io.wavfile
# Ensures that a file is passed in as an argument
if len(sys.argv) < 2:
print("Plays a wave file.\n\nUsage: %s filename.wav" % sys.argv[0])
sys.exit(-1)
file = sys.argv[1];
# Read the file
data = scipy.io.wavfile.read(file)
rate = data[0]
print data
print "rate = ", rate
print data[1]
print "format = ", data.dtype
出力
(44100, array([[0, 0],
[0, 0],
[0, 0],
...,
[0, 0],
[0, 0],
[0, 0]], dtype=int16))
rate = 44100
[[0 0]
[0 0]
[0 0]
...,
[0 0]
[0 0]
[0 0]]
format =
Traceback (most recent call last):
File "index.py", line 31, in <module>
print "format = ", data.dtype
AttributeError: 'tuple' object has no attribute 'dtype'
をdata'はタプルと 'はAttributeErrorです'ので:あなたは、あなたが解凍しませんでしたタプルの2番目の要素にアクセスする必要が
:あなたのコードでは、あなたはこれを持っています "タプル 'オブジェクトには属性' dtype 'がありません。それについては何が分かりませんか? – Julien
'scipy.io.wavfile.read'は' dtype'属性を持たないタプルを返します。ああ、すべてのステートメントをセミコロンで終了する必要はありません。 – TigerhawkT3
質問が更新されました。 – Catfish