我正在使用带有eclipse的pyDev。 我将外部代码导入到我的项目中,并且我收到了错误的缩进警告,这是因为外部代码的缩进与我的代码不同。
我该如何解决?
答案 0 :(得分:2)
在名为%PYTHON%/Tools/Scripts
的{{1}}文件夹中安装了一个脚本。我自己没有使用它,但根据文档,它修复了代码缩进到4个空格:
reindent.py
在Python源代码发行版中,它位于reindent [-d][-r][-v] [ path ... ]
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose) Verbose. Print informative msgs; else no output.
-h (--help) Help. Print this usage information and exit.
Change Python (.py) files to use 4-space indents and no hard tab characters.
Also trim excess spaces and tabs from ends of lines, and remove empty lines
at the end of files. Also ensure the last line ends with a newline.
If no paths are given on the command line, reindent operates as a filter,
reading a single source file from standard input and writing the transformed
source to standard output. In this case, the -d, -r and -v flags are
ignored.
You can pass one or more file and/or directory paths. When a directory
path, all .py files within the directory will be examined, and, if the -r
option is given, likewise recursively for subdirectories.
If output is not to standard output, reindent overwrites files in place,
renaming the originals with a .bak extension. If it finds nothing to
change, the file is left alone. If reindent does change a file, the changed
file is a fixed-point for future runs (i.e., running reindent on the
resulting .py file won't change it again).
The hard part of reindenting is figuring out what to do with comment
lines. So long as the input files get a clean bill of health from
tabnanny.py, reindent should do a good job.
The backup file is a copy of the one that is being reindented. The ".bak"
file is generated with shutil.copy(), but some corner cases regarding
user/group and permissions could leave the backup file more readable than
you'd prefer. You can always use the --nobackup option to prevent this.
目录中,在Ubuntu中,您可以安装python2.7-examples
或python3.4-examples
个包。
答案 1 :(得分:2)
" Bad indentaion"可以使用偏好设置关闭警告 - > PyDev - >编辑 - >代码分析 - >其他 - > "缩进问题以及标签和空格的混合"。
将值设置为"忽略"。那些标记应该消失。 :)