【问题标题】:Using a different comment style for commented out code in PyCharm在 PyCharm 中对注释掉的代码使用不同的注释样式
【发布时间】:2018-07-16 05:36:35
【问题描述】:

当使用 PyCharm 注释掉文本时(通过选择文本并点击键盘快捷键),它使用普通的# cmets,如下所示:

我不喜欢这看起来与实际 cmets 有多么相似(即我解释我的代码做了什么),所以它想使用不同风格的 cmets (##) 来注释掉代码:

def execute_evil_master_plan():
    ## # Start by hijacking a government satellite.
    ## # Doesn't matter which as long as it has a death laser.
    ## satellite = hijack_government_satellite()
    ## 
    ## # aim it towards the white house and fire the laser
    ## coords = google_maps.get_coordinates(WHITE_HOUSE)
    ## satellite.aim(target=coords)
    ## satellite.fire()

有没有办法在 PyCharm 中自定义这样的评论样式?

【问题讨论】:

    标签: python pycharm comments


    【解决方案1】:

    在多行注释前后使用“”。

    def execute_evil_master_plan():
        """
        # Start by hijacking a government satellite.
        # Doesn't matter which as long as it has a death laser.
        satellite = hijack_government_satellite()
    
        # aim it towards the white house and fire the laser
        coords = google_maps.get_coordinates(WHITE_HOUSE)
        satellite.aim(target=coords)
        satellite.fire()
        """
    

    【讨论】:

    • 我不喜欢这个解决方案,原因有很多:1)现在是函数的文档字符串。 2)它看起来像一个字符串,而不是评论。 3)我必须手动输入这些引号;我不能只按键盘快捷键,然后让 PyC​​harm 为我注释掉代码。
    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 2017-02-28
    • 2016-06-11
    • 1970-01-01
    • 2019-11-08
    相关资源
    最近更新 更多