网上的命令行都是相互抄的,根本没有实践过,先看看网上的yapf命令行:
--style='{based_on_style: google, indent_width: 4}'
Python3.7报错信息:yapf: "'{based_on_style:chromium,indent_width:4}'" is not a valid style or file path
查看源码逻辑
def _CreateConfigParserFromConfigFile(config_filename):
"""Read the file and return a ConfigParser object."""
if not os.path.exists(config_filename):
# Provide a more meaningful error here.
raise StyleConfigError(
'"{0}" is not a valid style or file path'.format(config_filename))
with open(config_filename) as style_file:
config = py3compat.ConfigParser()
config.read_file(style_file)
if config_filename.endswith(SETUP_CONFIG):
if not config.has_section('yapf'):
raise StyleConfigError(
'Unable to find section [yapf] in {0}'.format(config_filename))
elif config_filename.endswith(LOCAL_STYLE):
if not config.has_section('style'):
raise StyleConfigError(
'Unable to find section [style] in {0}'.format(config_filename))
else:
if not config.has_section('style'):
raise StyleConfigError(
'Unable to find section [style] in {0}'.format(config_filename))
return config
命令行输入的参数一直把它当作配置文件,更改后的命令行:
yapf --style "{based_on_style:chromium,indent_width:4}" C:\Users\anddyhua\test-align.py
或者
yapf --style "pep8" C:\Users\anddyhua\test-align.py