python - Use Regular expression with fileinput -


I am trying to change a variable stored in another file using regular expression. I have tried: Fileinput for row in

  r = re.compile (r "self \ .uid \ s * = \ s * ('\ w {12})') .input (['file.py'], inplace = True: print line.rale (r.match (line), sys.argv [1]),  

format file Variable:

  self.uid = '027FC8EBC2D1'  

I am trying to pass in a parameter in this format and the regular expression is verified To do that sys.argv [1] is the correct format and to find the stored variable in this file and find it with new variables The Rtisthapit.

Anybody can help Thanks for the help.

You can use re.sub which will match the regular expression And do one at a time:

  r = re.compile (r "(.uid \ s * = \ s *) '\ w {12}'") Fileinput For line in .input (['file.py'], inplace = True): Print R. Sub (r "\ 1 '% s'"% sys.argv [1], line),  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -