Feb-03-2019, 09:54 PM
(This post was last modified: Feb-04-2019, 03:51 AM by ichabod801.)
Hello
I can't replace more strings from file, i use two ways:
I can't replace more strings from file, i use two ways:
- function lambda
- expr regulier
#! /bin/python
import re
import sys
import fileinput
import os
stripped = lambda s: "".join(i for i in s if 31 < ord(i) < 127)
#en dur ça marche
print(stripped('\xe2\x80\x9chttp://www.google.com\xe2\x80\x9d blah blah#%#@$^blah'))
for line in fileinput.input('fic.txt'):
#with exrp regu
line1 = re.sub(r'[^\x00-\x7f]', r'', line.rstrip())
print(line1)
####################
#with lambda
print(stripped(line.rstrip()))Output:>cat fic.txt
\xe2\x80\x9chttp://www.google.com\xe2\x80\x9d blah blah#%#@$^blahThanks for help
