2017-09-08 12 views
-1

ユーザからの入力後にエラーが発生しましたが、常にsetオブジェクトに属性がありません。私は他の質問を見てきましたが、私のシナリオでは何の成功もありませんでした。私は多くのことを試しました。基本的にプログラムには私が作成した暗号があり、ユーザーの文字を私が持っている暗号アルファベットに置き換えたいのです。私は翻訳を機密目的のために置き換えました。誰かがこれで私を助けてくれることを願っています。Python 2.7のエラー:raw_input条件を設定した後、 'set'オブジェクトに属性 '__GETITEM__'がありません

cache_list = { 
'result' 
} 

usr = raw_input("Usr: ") 



if 'a' in usr: 
result1 = usr.replace('a', "hash1" , 1000000000) 
cache_list['result'].append(result1) 


if 'b' in usr: 
    result2 = usr.replace('b', "hash2" , 1000000000) 
    cache_list['result'].append(result2) 

if 'c' in usr: 
cache_list['result3'] = usr.replace('c', "hash3" , 1000000000) 
cache_list['result'].append(result3) 


if 'd' in usr: 
result4 = usr.replace('d', "hash4" , 1000000000) 
cache_list['result'].append('result4' 
           ) 


if 'e' in usr: 
result5 = usr.replace('e', "hash5" , 1000000000) 
cache_list['result'].append(result5) 


if 'f' in usr: 
result6 = usr.replace('f', "hash6" , 1000000000) 
cache_list['result'].append(result6) 

if 'g' in usr: 
result7 = usr.replace('g', "hash7" , 1000000000) 
cache_list['result'].append(result7) 


if 'h' in usr: 
result8 = usr.replace('h', "hash8" , 1000000000) 
cache_list['result'].append(result8) 


if 'i' in usr: 
result9 = usr.replace('i', "hash10" , 1000000000) 
cache_list['result'].append(result9) 


if 'j' in usr: 
result10 = usr.replace('j', "hash11" , 1000000000) 
cache_list['result'].append(result10) 


if 'k' in usr: 
result11 = usr.replace('k', "hash12" , 1000000000) 
cache_list['result'].append(result11) 


if 'l' in usr: 
result12 = usr.replace('l', "hash13" , 1000000000) 
cache_list['result'].append(result12) 


if 'm' in usr: 
result13 = usr.replace('m', "hash14" , 1000000000) 
cache_list['result'].append(result13) 


if 'n' in usr: 
result14 = usr.replace('n', "hash15" , 1000000000) 
cache_list['result'].append(result14) 


if 'o' in usr: 
result15 = usr.replace('o', "hash17" , 1000000000) 
cache_list['result'].append(result15) 


if 'p' in usr: 
result16 = usr.replace('p', "hash18" , 1000000000) 
cache_list['result'].append(result16) 



if 'q' in usr: 
result17 = usr.replace('q', "hash19" , 1000000000) 
cache_list['result'].append(result17) 


if 'r' in usr: 
result18 = usr.replace('r', "hash20" , 1000000000) 
cache_list['result'].append(result18) 



if 's' in usr: 
result19 = usr.replace('s', "hash21" , 1000000000) 
cache_list['result'].append(result19) 




if 't' in usr: 
result20 = usr.replace('t', "hash22" , 1000000000) 
cache_list['result'].append(result20) 




if 'u' in usr: 
result21 = usr.replace('u',"hash23" , 1000000000) 
cache_list['result'].append(result21) 



if 'v' in usr: 
result22 = usr.replace('v',"hash24" , 1000000000) 
cache_list['result'].append(result22) 



if 'w' in usr: 
result23 = usr.replace('w',"hash26" , 1000000000) 
cache_list['result'].append(result23) 




if 'x' in usr: 
result24 = usr.replace('x',"hash27" , 1000000000) 
cache_list['result'].append(result24) 





if 'y' in usr: 
result25 = usr.replace('y',"hash28" , 1000000000) 
cache_list['result'].append(result25) 





if 'z' in usr: 
    result26 = usr.replace('z',"hash29" , 1000000000) 
cache_list['result'].append(result26) 





if ' ' in usr: 
result27 = usr.replace(' ', "space" , 1000000000) 
cache_list['result'].append(result27) 



print cache_list[result] 
+0

あなたが持っている問題は何ですか?あなたはどんなふるまいを見ていますか、何を見たいと思いますか? – Engineero

答えて

2

あなたcache_list変数を初期化するときは、(おそらく誤って)セットの代わりに辞書を作成しました。使用してみてください:

cache_list = {"result": ""} 

これは辞書に一つのキーresultを作成し、""(空の文字列)であると、その値を設定します。ここで

は、コンソールの例である:

>>> cache_list = {"result"} 
>>> type(cache_list) 
<type 'set'> 

通訳を訴え、このセットは__GETITEM__機能はありません。

>>> cache_list = {"result": ""} 
>>> type(cache_list) 
<type 'dict'> 
>>> cache_list["result"] 
'' 

概要::{"result"}を設定作成しますが、{"result": ""}辞書を作成します。しかし、私の提案の初期化を使用すると、正しい型を取得します。

0

リストに保存するので、cache_listはこの方法でなければなりません:

cache_list = {"result": []} 

usr = raw_input("Usr: ") 

if 'a' in usr: 
    result1 = usr.replace('a', "hash1", 1000000000) 
    print result1 
    cache_list['result'].append(result1) 

if 'b' in usr: 
    result2 = usr.replace('b', "hash2", 1000000000) 
    cache_list['result'].append(result2) 

print cache_list["result"] 
関連する問題