【问题标题】:Updating the method references on VS code更新 VS 代码上的方法引用
【发布时间】:2022-01-09 06:56:34
【问题描述】:

我很难弄清楚如何从 vscode 更新方法的选定引用。右键单击方法名称不会提供选择和更新引用的选项。 Python 和 vscode 的新手,并试图找出它周围的细微差别。请有人帮我解决这个问题!

这是课程 - 我有一个课程Player_Account

class Player_Account:

    def __init__(self,owner,balance):
        self.owner = owner
        self.balance = balance

    def deposit(self,balance):
        self.balance += balance
        return "Amount added to players pot !"

    def withdraw(self,amount): # I need to update this method name to withdraw_amount
        if self.balance<amount:
            return "Funds Unavailable"
        else:
            self.balance -= amount
            return "Money added to hand !"

    def __str__(self):
        return f"Account owner : {self.owner} has outstanding balance of {self.balance}"

另一个班级Player

class Player:
    def __init__(self,name):
        self.name=name
        self.hand = []
        self.player_account:Player_Account = Player_Account(name,0)

    def initial_money(self,amount):
        self.player_account.balance = amount

    def player_won_the_hand(self,amount):
        self.player_account.deposit(amount)
        return True

    def player_betting_amount_for_the_round(self,amount):
        value = self.player_account.withdraw(amount) # I need this reference to be automatically updated as well
        if value == 'Funds Unavailable':
            return False
        else:
            return True

【问题讨论】:

  • return value != 'Funds Unavailable'

标签: python visual-studio-code


【解决方案1】:

我刚试过。

  • 将光标设置在def withdraw
  • F2(重命名符号)
  • 将名称更改为withdraw_amount,然后按Enter
  • 这需要几秒钟,但两者都已更改

我使用 PyLance。

【讨论】:

  • 这实际上解决了我当前的问题,但是如果我必须只选择几个参考文献,会有一个选项吗?另外,您是否在具有多个参考的大型项目中尝试过此方法?
  • @chapter473 为什么您只想更改一些参考文献?如果函数名变了应该都变了,你有没有看Find All ReferencesShift+Alt+F12,看看编辑器的上下文菜单
猜你喜欢
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-22
相关资源
最近更新 更多