本文目錄一覽:
python怎麼整體一次性刪井號
您好,很高興能夠為您解答。python去掉井號鍵方法如下:快捷鍵:ctrl+/取消注釋ctrl+/(除了mac本)cmd+/(mac本)
python編個腳本,用來刪除注釋‘//’後的內容。
讀取文件的沒一行,然後找到‘//’的位置,用python的切片功能就可以了
python如何標註掉代碼
python標註掉代碼的方法:1、選中需要標註掉的代碼;2、按下鍵盤上的【ctrl+/】快捷鍵即可標註掉代碼。如果要取消標註,可以再次按下鍵盤上的【ctrl+/】快捷鍵。
方法一:(推薦)
(推薦教程:Python入門教程)
1、注釋
選中要注釋的段落,按下 ctrl+/ 快捷鍵,效果如下:
2、取消注釋
再按一下 ctrl+/ 快捷鍵即可取消注釋。
方法二:
將一整段用三個雙引號括起來即可,如圖:
python移除注釋方法
批量去除指定源文件夾中的py文件的注釋,並生成拷貝與指定目的文件夾
#!/usr/bin/python
# -*- coding: GBK -*-
#writer:xmnathan
#py文件去注釋
import re
import os
import ConfigParser
Python=’CleanNote’
def ReadIni(path,section,option):#文件路徑,章節,關鍵詞
#讀取ini
cf=ConfigParser.ConfigParser()
cf.read(path)
value=cf.get(section,option)#如果用getint()則直接讀取該數據類型為整數
return value
def IsPassLine(strLine):
#是否是可以忽略的行
#可忽略行的正則表達式列表
RegularExpressions=[“””/’.*#.*/'”””,”””/”.*#.*/””””,
“””/’/’/’.*#.*/’/’/'”””,”””/”/”/”.*#.*/”/”/””””]
for One in RegularExpressions:
zz=re.compile(One)
if re.search(zz,strLine)==None:
continue
else:
return True#有匹配 則忽略
return False
def ReadFile(FileName):
#讀取並處理文件
fobj=open(FileName,’r’)
AllLines=fobj.readlines()
fobj.close()
NewStr=”
LogStr=’/n%20s/n’%(FileName.split(‘//’)[-1])#輸出的日誌
nline=0
for eachiline in AllLines:
index=eachline.find(‘#’)#獲取帶注釋句‘#’的位置索引
if index==-1 or nline3 or IsPassLine(eachline):
if eachiline.strip()!=”:#排除純空的行
NewStr=NewStr+eachiline
else:
if index!=0:
NewStr=NewStr+eachiline[:index]+’/n’#截取後面的注釋部分
LogStr+=”ChangeLine: %s/t%s”%(nline,eachline[index:])
nline+=1
return NewStr,LogStr
def MakeCleanFile(SrcPath,DescPath,FileList):
fLog=open(DescPath+’//’+’CleanNoteLog.txt’,’w’)
for File in FileList:
curStr,LogStr=ReadFile(SrcPath+’//’+File)
fNew=open(DescPath+’//’+File,’w’)
fNew=write(curStr)
fNew.close()
fLog.write(LogStr)
fLog.close()
def Main():
#從ini獲取源文件夾及目標文件夾路徑
IniPath=os.getcwd()+’//’+PtName+’.ini’
SrcPath=ReadIni(IniPath,PyName,’SrcPath’)#源文件夾
DescPath=ReadIni(IniPath,PyName,’DescPath’)#目的文件夾
#如果目的文件夾不存在,創建之
if not os.path.exists(DescPath):
os.makedirs(DescPath)
FileList=[]
for files in os.walk(SrcPath):
for FileName in files[2]:
if FileName.split(‘.’)[-1]==’py’:
FileList.append(FileName)
MakeCleanFile(SrcPath,DescPath,FileList)
if __name__==’__main__’:
Main()
print ‘End’
os.system(‘pause’)
CleanNote.ini的格式
[CleanNote]
SrcPath=E:/test
DescPath=E:/test/newfiles
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/271300.html