2017-12-11 20 views
0

私は新しいバージョンのPyCharmを使ってPythonを扱います。私はクラスの項目「未解決の属性参照

のための「ItemLocation」

未解決の属性参照を受けていますが、アプリケーションはエラーなしまたはクラッシュし、任意のアイデアと罰金起動しますか?

class Item: 
    def __init__(self, state = '', location = '', realm = 'All', index =- 1): 
     self.__dict__ = { 
      'ActiveState': state, 
      'ItemEquipped': 0, 
      'ItemLocation': location, # <-- DEFINED HERE 
      'ItemRealm': realm, 
      'ItemLevel': '51', 
      'ItemQuality': '100', 
      'ItemType': '', 
      'ItemName': '', 
      'ItemAFDPS': '', 
      'ItemSpeed': '', 
      'ItemBonus': '', 
      'ItemSource': '', 
      'LeftHand': '', 
      'ItemDamageType': '', 
      'ItemRestrictions': list(), 
      'ItemNotes': '', 
      'ItemRequirement': '', 
      'TemplateIndex': index, 
     } 

     self.ItemSlotList = list() 

     if self.ItemLocation in SlotList['Jewelery']: # <-- HERE 
      self.ActiveState = 'drop' 
      self.ItemEquipped = 2 
     elif self.ItemLocation in SlotList['Armor']: # <-- HERE 
      self.ActiveState = 'crafted' 
      self.ItemEquipped = 2 
     elif self.ItemLocation in SlotList['Weapons']: # <-- HERE 
      self.ActiveState = 'drop' 
      self.ItemEquipped = 0 
     elif self.ItemLocation in SlotList['Mythical']: # <-- HERE 
      self.ActiveState = 'drop' 
      self.ItemEquipped = 2 

     # TODO: DETERMINE 'ItemEquipped' FOR WEAPONS BASED ON CLASS SELECTION 

     self.ItemSlotList = self.makeItemSlots() 

申し訳ありませんが、私はまだ学習しています。私はPython 3とPyQt5を実行しています

+0

この未解決の属性参照を受け取っている状況は不明です。 –

+0

'self .__ dict__'への割り当ては、逆です - 私はそれが許されても驚いています。あなたの '__init __()'でインスタンス変数を初期化する通常の方法は 'self.ActiveState = state'のような一連のステートメントです。 – jasonharper

+0

私はこれを見て少しショックを受けていました。私は現在、完全な混乱であるアプリケーションを書き換えています。これは私が見たいくつかの例の1つに過ぎません。 –

答えて

0

私はPyCharmを使用しませんが、動的割り当てが可能なので__dict__割り当てをチェックしないと仮定していますので、チェックするためにコードを実行する必要があります。

+0

私は物事が意図したとおりに働いていることを保証することができます。おそらくPyCharmがこれをチェックしていないあなたの権利、それは奇妙なことである。 –