Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import print_function #Compatibilidade func print python 2/3
- from os.path import isfile
- def FileLineFilter(StrFilter, FileIn, FileOut):
- #Remover as linhas que iniciem ou teminem com determinada expressão
- with open(FileIn, 'r') as inf, open(FileOut, 'w') as ouf:
- for LineStr in inf:
- if (not LineStr.startswith(StrFilter)) and (not LineStr.endswith(StrFilter + '\n')):
- ouf.write(LineStr)
- #python close files here
- #File names and filter
- StrFilter = '#'
- FileIn = 'FileNameIN.txt'
- FileOut = 'FileNameOut.txt'
- #Validate files
- assert isfile(FileIn), 'Arquivo de entrada (%s) nao existe. Verifique.' %(FileIn)
- assert not isfile(FileOut), 'Arquivo de saida (%s) ja existe. Verifique.' %(FileOut)
- FileLineFilter(StrFilter, FileIn, FileOut)
- with open(FileOut, 'r') as f:
- print(f.read())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement