Skip to content

Commit 467a24b

Browse files
committed
added a script to expand tabs to spaces for PEP 8 compliance
1 parent 80d9447 commit 467a24b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

expand_tabs.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
import re
3+
4+
reg_pyfile=re.compile(r'.*\.py$',re.I)
5+
6+
def expand_tabs(file0):
7+
'''
8+
This function takes the name of a python source file, expands all tabs to 4 spaces (for
9+
PEP 8 compliance), and rewrites the file in place.
10+
'''
11+
str_file_contents=open(file0,'rb').read()
12+
str_pep_contents=str_file_contents.replace('\x09',4*'\x20')
13+
open(file0,'wb').write(str_pep_contents)
14+
return None
15+
16+
def pepify_directory(path_root):
17+
for (path,subdir,lst_file) in os.walk(path_root):
18+
for file0 in (file1 for file1 in lst_file if reg_pyfile.match(file1)):
19+
expand_tabs(os.path.join(path,file0))
20+
print(os.path.join(path,file0))
21+
pass
22+
pass
23+
return None
24+
25+
if __name__=='__main__':
26+
pepify_directory('.')
27+
pass
28+

0 commit comments

Comments
 (0)