Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Pycharm不';t在对象内部显示对象方法的建议_Python 3.x - Fatal编程技术网

Python 3.x Pycharm不';t在对象内部显示对象方法的建议

Python 3.x Pycharm不';t在对象内部显示对象方法的建议,python-3.x,Python 3.x,我正在看制作RGB游戏的教程,我很困惑为什么pycharm在一个案例中不给出建议 情况是,我从一个名为“拼写”的类中创建了如下对象 # Create Black Magic fire = Spell("Fire", 10, 100, "black") thunder = Spell("Thunder", 10, 100, "black") blizzard = Spell("Blizzard", 10, 100, "black") meteor = Spell("Meteor", 20, 200

我正在看制作RGB游戏的教程,我很困惑为什么pycharm在一个案例中不给出建议

情况是,我从一个名为“拼写”的类中创建了如下对象

# Create Black Magic
fire = Spell("Fire", 10, 100, "black")
thunder = Spell("Thunder", 10, 100, "black")
blizzard = Spell("Blizzard", 10, 100, "black")
meteor = Spell("Meteor", 20, 200, "black")
quake = Spell("Quake", 14, 140, "black")

# Create White Magic
cure = Spell("Fire", 12, 120, "white")
cura = Spell("Cure", 18, 200, "white")
然后使用这些对象,我将它们作为另一个不同类(角色)的对象(“玩家”)的属性之一

然后我让用户选择魔术

magic_choice = int(input("Choose your magic")) - 1

magic_dmg = player.magic[magic_choice].generate_damage()
但是当我试着写作的时候

magic_dmg = player.magic[magic_choice].generate_damage()
Pycharm找不到存储在不同文件中的“.generate_damage()”方法。代码可以工作,但不能给出建议。原因可能是什么

class Character:
    def __init__(self, hp, mp, atk, df, magic):
        self.max_hp = hp
        self.hp = hp
        self.max_mp = mp
        self.mp = mp
        self.atk_l = atk - 10
        self.atk_h = atk + 10
        self.df = df
        self.magic = magic


class Spell:   
    def __init__(self, name, cost, dmg, type):
        self.name = name
        self.cost = cost
        self.dmg = dmg
        self.type = type

    def generate_damage(self):
        mag_l = self.dmg - 15
        mag_h = self.dmg + 15
        return random.randrange(mag_l, mag_h)

你没有说是什么类型的
self.magic
,所以它不可能知道这是一个
拼写列表

您需要使用以下命令对属性进行注释:


实际上,我做了spell=player.magic[magic_choice]并编写了spell.generate_damage(),建议出现在“spell”中。但如果我只使用了“player.magic[magic_choice]”。虽然建议相同,但没有看到任何建议。
class Character:
    def __init__(self, hp, mp, atk, df, magic):
        self.max_hp = hp
        self.hp = hp
        self.max_mp = mp
        self.mp = mp
        self.atk_l = atk - 10
        self.atk_h = atk + 10
        self.df = df
        self.magic = magic


class Spell:   
    def __init__(self, name, cost, dmg, type):
        self.name = name
        self.cost = cost
        self.dmg = dmg
        self.type = type

    def generate_damage(self):
        mag_l = self.dmg - 15
        mag_h = self.dmg + 15
        return random.randrange(mag_l, mag_h)
from typing import List

. . . 

# magic is a list of spells
self.magic: List[Spell] = magic