简体   繁体   English

我需要哪种对象才能使用fix_multiple_files的options参数?

[英]What kind of object do I need to use the options parameter of fix_multiple_files?

I need to create a simple script for fixing indentation in python scripts of the repository. 我需要创建一个简单的脚本来修复存储库的python脚本中的缩进。 I found fix_multiple_files in autopep8 module: 我发现fix_multiple_files autopep8模块:

import autopep8

autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options={'recursive': 1})

I'm getting this every time I run the script: 我每次运行脚本时都会得到这个:

Traceback (most recent call last):
  File "/home/playrix/work/ci-teamcity/scripts/1.py", line 4, in <module>
    autopep8.fix_multiple_files('/home/playrix/work/ci-teamcity/scripts/', options='')
  File "/home/playrix/.local/lib/python2.7/site-packages/autopep8.py", line 3897, in fix_multiple_files
    filenames = find_files(filenames, options.recursive, options.exclude)
AttributeError: 'str' object has no attribute 'recursive'

How correctly noticed johnsharpe it was argparse.Namespace . 如何正确地注意到johnsharpe是argparse.Namespace And the best way to get it was: 最好的方法是:

opt = autopep8.parse_args(arguments=['recursive', '--in-place', '--aggressive'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM