0

我刚刚为 python 安装了 autopep8 格式化程序,当我尝试从文档中格式化示例代码时,它没有正确格式化。您可以在此链接
中看到正确格式的代码

这是格式化代码后我在编辑器上实际得到的:

import math
import sys


def example1():
    # This is a long comment. This should be wrapped to fit within 72 characters.
    some_tuple = (1, 2, 3, 'a')
    some_variable = {'long': 'Long code lines should be wrapped within 79 characters.',
                     'other': [math.pi, 100, 200, 300, 9876543210, 'This is a long string that goes on'],
                     'more': {'inner': 'This whole logical line should be wrapped.', some_tuple: [1,
                                                                                                  20, 300, 40000, 500000000, 60000000000000000]}}
    return (some_tuple, some_variable)


def example2(): return {'has_key() is deprecated': True}.has_key({'f': 2}.has_key(''))


class Example3(object):
    def __init__(self, bar):
        # Comments should have a space after the hash.
        if bar:
            bar += 1
            bar = bar * bar
            return bar
        else:
            some_string = """
                       Indentation in multiline strings should not be touched.
Only actual code should be reindented.
"""
            return (sys.path, some_string)

ps:我还为 VSCode 安装了autopep8 扩展,但它也没有像文档中所示那样格式化代码。

4

0 回答 0