【python】python代碼的縮進


未添加着色功能,這個比較麻煩,好比變量是什麼色,函數是什麼色,須要使用正則。python


使用blog裏自帶的python代碼着色,更改以下:print('<pre class="brush:python;toolbar:false">' + all +  '</pre>')ide


效果及代碼以下:函數

# -*- coding: utf-8 -*-  
codedic={'"':'&quot;',"'":'&#39;','<':'&lt;','>':'&gt;','&':'&amp;'}
codekey=codedic.keys()
filename=input('input file path:')
print(filename)
f=open(filename,'r')
all=''
for line in f:
    ltmp=''
    for c in line:
        if c in codekey:
            ltmp+=codedic[c]
        elif ord(c)==9:
            ltmp+='&nbsp;&nbsp;'
        elif ord(c)==32:
            ltmp+='&nbsp;'
        else:
            ltmp+=c
            
    all=all+'<p style="margin-top: 0px; margin-bottom: 0px;">'+ltmp+'</p>'
f.close()
    
print('<pre class="brush:python;toolbar:false">' + all +  '</pre>')
相關文章
相關標籤/搜索