Я новичок в Python, но опытный ветеринар на других языках, но почему data.dtype выдает ошибку AttributeError: 'tuple' object has no attribute 'dtype'
и как я могу получить значение dtype?AttributeError: объект 'tuple' не имеет атрибута 'dtype'
Из this блога, похоже, я должен быть в состоянии только сделать 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: ' tuple 'не имеет атрибута dtype''. Что непонятно? – Julien
'scipy.io.wavfile.read' возвращает кортеж, который не имеет атрибута' dtype'. О, и вам не нужно заканчивать каждое утверждение точкой с запятой. – TigerhawkT3
Обновленный вопрос, чтобы быть более ясным – Catfish