In the python language, beginners hardest elusive than the code indent and alignment problems, different code indent the code represents the time python code belongs to the code block (range), batch processing needs, which how does it work?
The edited mainly for the good of the code, which is inserted in the new code block, the remaining code indentation and comments batch operation.
(A) sample code fragment
def staLocation(sourceArrayStrCoor):
""" :param sourceArrayStrCoor: 传入的未处理原始字符数据 :return: para:已处理的结果数据 """ print(sourceArrayStrCoor[3]) print("分隔测试") #过滤字符串左右的所有空格 print(re.split('[\s]', sourceArrayStrCoor[3].strip())) #处理非空格(负号)连接问题 rth = re.split('[\s]', sourceArrayStrCoor[3].strip()) # 遍历结果,根据连接处为“-”来判断 for i in range(len(rth)): # 出现单负号连接情况,负号都是从第二个开始 if 19 < len(rth[i]) < 58: pass
The main function call output:
0.792000000000E+05 0.391155481338E-07 0.306778842479E+01-0.856816768646E-07 分隔测试 ['0.792000000000E+05', '0.391155481338E-07', '0.306778842479E+01-0.856816768646E-07']
(B) Target: at the beginning of loop for adding statements to achieve a plurality of data processing
Question: At this point, we found that after joining the block of code ownership has changed, after the code for the property belongs to the for loop, should be unified indented character.
But too much code that we want to do one by one to adjust the alignment?
(C) Solution: Batch indentation
Shortcut keys: Tab to indent, Shift Tab to indent reverse
3.1 Select the area to indent the code, click Tab to;
3.2 Effects
for i in range(5):
print(sourceArrayStrCoor[3])
print("分隔测试") #过滤字符串左右的所有空格 print(re.split('[\s]', sourceArrayStrCoor[3].strip())) #处理非空格(负号)连接问题 rth = re.split('[\s]', sourceArrayStrCoor[3].strip()) # 遍历结果,根据连接处为“-”来判断 for i in range(len(rth)): # 出现单负号连接情况,负号都是从第二个开始 if 19 < len(rth[i]) < 58: pass
3.3 Main results of function calls
12 10 6 20 22 0 0.0-0.101987272501E-03 0.409272615798E-11 0.000000000000E+00
分隔测试
['12', '10', '', '6', '20', '22', '', '0', '', '0.0-0.101987272501E-03', '0.409272615798E-11', '0.000000000000E+00'] 0.380000000000E+02-0.481250000000E+01 0.461804950315E-08-0.139801880836E+01 分隔测试 ['0.380000000000E+02-0.481250000000E+01', '0.461804950315E-08-0.139801880836E+01'] -0.188127160072E-06 0.349152914714E-02 0.719912350178E-05 0.515366796684E+04 分隔测试 ['-0.188127160072E-06', '0.349152914714E-02', '0.719912350178E-05', '0.515366796684E+04'] 0.792000000000E+05 0.391155481338E-07 0.306778842479E+01-0.856816768646E-07 分隔测试 ['0.792000000000E+05', '0.391155481338E-07', '0.306778842479E+01-0.856816768646E-07'] 0.971417938748E+00 0.245656250000E+03-0.405309810049E+00-0.809212278368E-08 分隔测试 ['0.971417938748E+00', '0.245656250000E+03-0.405309810049E+00-0.809212278368E-08']
3.4 Reverse indentation test: select the area to indent, press Shift + Tab
If you need to comment out a lot of code segment (not delete), how does it work?
(Four) shortcut Ctrl + /
Select and press the shortcut key combination of the above.
for i in range(5):
# print(sourceArrayStrCoor[i])
# print("分隔测试") # #过滤字符串左右的所有空格 # print(re.split('[\s]', sourceArrayStrCoor[i].strip())) # #处理非空格(负号)连接问题 # rth = re.split('[\s]', sourceArrayStrCoor[i].strip()) # # 遍历结果,根据连接处为“-”来判断 # for i in range(len(rth)): # # 出现单负号连接情况,负号都是从第二个开始 # if 19 < len(rth[i]) < 58: pass