2014-11-19 6 views
0

나는 이클립스와 함께 pyDev를 사용하고있다. 내 프로젝트에 외부 코드를 가져오고 잘못된 들여 쓰기 경고가 표시됩니다. 외부 코드가 내 코드와 다른 들여 쓰기를하기 때문입니다.잘못된 들여 쓰기 오류를 제거하는 방법? 이클립스 파이썬

어떻게 해결할 수 있습니까?

+0

일부 프로그램 탭을 사용하여, 다른 용도의 공간 들여 쓰기를 만들 수 있습니다. 필자는 일반적으로 메모장 + + (보기 -> 기호보기 -> 모든 문자보기)를 사용하여 들여 쓰기를 표시하고 수동으로 수정합니다. 그러나 많은 코드 줄이있을 때 약간 지루할 수도 있습니다. –

+0

예 코드 줄이 많아서 수동으로 할 수 없었습니다. – david

+0

아마도 다음과 같이해야합니다. http://stackoverflow.com/questions/407929/how-do-i-change-eclipse-to-use-spaces-instead-of-tabs – Dyrborg

답변

2

reindent.py이라는 %PYTHON%/Tools/Scripts 폴더에 스크립트가 설치되어 있습니다. 내가 직접 사용하지 않은,하지만 문서에 따라 4 개 공간에 코드의 들여 쓰기 수정 : 그것이 Tools/scripts 디렉토리에있는 파이썬 소스 배포판에서

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. 

, 그리고 우분투에 설치할 수 있습니다 python2.7-examples 또는 python3.4-examples 패키지

+0

이것은 링크 전용 답변이 아니며'reindent.py'는 Windows Python과 함께 제공됩니다 (Ubuntu에는 설치되어 있지 않지만). 외부 코드 가져 오기가 단방향 일 경우 (즉, 패치가 적용되지 않을 경우) 들여 쓰기를 수정하고 들여 쓰기 경고를 남기지 마십시오 (또는 들여 쓰기 문제를 * Error *로 설정하십시오). OTOH, PyDev도이 작업을 수행해야합니다. –

+0

@cfi : ** ** ** 링크 전용 답변이 아닙니다. 여기에는 파이썬 소스 파일을 다시 뒤섞는 스크립트가 있다는 것을 설명합니다 *. –

+0

나는 당신을 링크로 알리지 않았다. 제 통지서를 다시 수정하십시오. –

2

환경 설정 -> PyDev -> 편집기 -> 코드 분석 -> 기타 -> "들여 쓰기 문제 및 탭과 공백 혼합"에서 "잘못된 들여 쓰기"경고를 끌 수 있습니다.

일단 값이 "무시"로 설정됩니다. 그 표식은 사라져야합니다. :)

enter image description here