2016-08-14 28 views
-1

このエラーメッセージを私に説明することはできますか?AttributeError: 'tuple'オブジェクトに 'copy'属性がありません

# make a copy or hand is destroyed by your test 
remaining = hand.copy() 

結果:

AttributeError: 'tuple' object has no attribute 'copy' 

は、私がこれを行うことができます。

remaining = copy.copy(hand) 

この返す:私はので、達成しようとしているものをオフにスロー

(None, {hand...}) 

関数は、検索するとFalseを返しますNone戻り値を返します。

def deal_hand(n): 
""" 
Returns a random hand containing n lowercase letters. 
At least n/3 the letters in the hand should be VOWELS. 

Hands are represented as dictionaries. The keys are 
letters and the values are the number of times the 
particular letter is repeated in that hand. 

n: int >= 0 
returns: dictionary (string -> int) 
""" 
hand={} 
num_vowels = n/3 

for i in range(num_vowels): 
    x = VOWELS[random.randrange(0,len(VOWELS))] 
    hand[x] = hand.get(x, 0) + 1 

for i in range(num_vowels, n):  
    x = CONSONANTS[random.randrange(0,len(CONSONANTS))] 
    hand[x] = hand.get(x, 0) + 1 

return hand 

EDIT: 私はさらに道に沿って手を変え、代わりに辞書のそれのうちのタプルを作成し

これは手を作成する機能です。ありがとう!

+0

タプルには 'copy'メソッドがないので、エラーメッセージが表示されます。なぜあなたはタプルで 'copy'を呼び出そうとしていますか? – BrenBarn

+0

私は手元にあるテストを実行し、それを破壊しないので、 – Chris

+0

あなたの状況に対してより多くのコンテキストがあれば良いでしょう。タプルには 'copy'というメソッドがないので無効であるタプルに対してcopy()を呼び出そうとしていることは明らかです。しかし、なぜあなたがそれをしようとしているのかわかりません。 –

答えて

1

エラーは非常に明確です:あなたはcopyに電話しようとするタプルがあります。

handにあるオブジェクトは、目的のオブジェクトではなくタプルであるようです。

+0

あなたの質問を削除できるようにあなたの答えを削除できますか?ありがとう! – Chris

関連する問題