2016-05-05 3 views
0

エディタ内のすべてのタブが4つのスペースに変換されていることを確認しました。私はPython 2.7でコーディングしています。いくつかのサブクラスに1つの引数を追加した後、突然IndentationErrorが発生します。ここでタブはスペースに変換されますが、まだインデントエラーが発生しています

はエラーメッセージです:ここで

Traceback (most recent call last): 
    File "C:\Users\XXXXXXX\Dropbox\RPG\game.py", line 1, in <module> 
    from player import Player 
    File "C:\Users\XXXXXXX\Dropbox\RPG\player.py", line 1, in <module> 
    import items 
    File "C:\Users\XXXXXXX\Dropbox\RPG\items.py", line 16 
    self.weight = 1 
       ^
IndentationError: unindent does not match any outer indentation level  
Press any key to continue . . . 

は元のコードです:

import random 

class Weapon: 
    def __init__(self): 
     raise NotImplementedError("Do not create raw Weapon objects.") 

    def __str__(self): 
     return "\n{}\n=====\n{}\nValue: {}\nDamage: {}\nWeight: {} lb.\n".format(self.name, self.description, self.value, self.damage, self.weight) 

class Dagger(Weapon): 
    def __init__(self): 
     self.name = "Dagger" 
     self.description = "" 
     self.value = 2 
     self.damage = random.randint(1, 4) 
     self.weight = 1 

class Longsword(Weapon): 
    def __init__(self): 
     self.name = "Longsword" 
     self.description = "" 
     self.value = 15 
     self.damage = random.randint(1, 8) 
     self.weight = 4 

class Armor: 
    def __init__(self): 
     raise NotImplementedError("Do not create raw Armor objects.") 

    def __str__(self): 
     return "\n{}\n=====\n{}\nValue: {}\nArmor/Shield Bonus: {}\nWeight: {} lb.\n".format(self.name, self.description, self.value, self.armor_bonus, self.weight) 

    def modify_player(self, player): 
     if self in player.inventory(): 
      player.armor_bonus = player.armor_bonus + self.armor_bonus 

class PaddedArmor(Armor): 
    def __init__(self): 
     self.name = "Padded Armor" 
     self.description = "" 
     self.value = 5 
     self.armor_bonus = 1 
     self.weight = 10 

class LeatherArmor(Armor): 
    def __init__(self): 
     self.name = "Leather Armor" 
     self.description = "" 
     self.value = 10 
     self.armor_bonus = 2 
     self.weight = 15 

class Consumable: 
    def __init__(self): 
     raise NotImplementedError("Do not create raw Consumable objects.") 

    def __str__(self): 
     return "{} (+{} HP)".format(self.name, self.healing_value) 

class HealerKit(Consumable): 
    def __init__(self): 
     self.name = "Healer's kit" 
     self.healing_value = 50 
     self.value = 50 
     self.weight = 1 

class Bread(Consumable): 
    def __init__(self): 
     self.name = "Bread" 
     self.healing_value = 10 
     self.weight = 0.5 

class Cheese(Consumable): 
    def __init__(self): 
     self.name = "Cheese" 
     self.healing_value = 8 
     self.value = 1 
     self.weight = 0.5 
+1

あなたのコードを質問からスクリプトにコピー/ペーストするとどうなりますか? – jDo

+2

コードを貼り付けて実行しようとしましたが、エラーは報告されませんでした。このコード(ここに投稿したもの)を元のコードに貼り付けてください。 – pmaniyan

+0

コードにインデントエラーがありません。 (少なくともコードはここに投稿されました) –

答えて

0

あなたのエディタが新たに挿入されたテキストのタブ文字を挿入されていないことを確認します。 TABを別の場所でカットアンドペーストすることができます。

編集者はデフォルトでTABを4スペースにすることがよくありますが、PythonではTAB が8スペースであると想定しています(これは長年の規約です)。

また、エディタで機能を探して、タブが表示されていることを確認する必要があります。

あなたのエディタでは、プログラミングのためのより良いものを探したいかもしれません。

関連する問題