Nov-16-2019, 11:45 PM
Hello community, hope everyone is having a good time.
I'm doing a pretty easy script, look for a certain format of values in a file then repeat them three times in an output file.
Example:
Find -> 0.875*V
Substituted -> =0.875*V<TAB>=0.875*V<TAB>=0.875*V<TAB>
This regular expression already has worked us in Perl but I have not been able to figure out why it fails in Python.
From the results I can see the group is captured correctly but it is substituted with SOH character(Start Of Header) instead of captured value.
Our work environment:
- Windows 10 Pro
- Python 3.8
Output file results:
Thanks for the time reading this post.
I'm doing a pretty easy script, look for a certain format of values in a file then repeat them three times in an output file.
Example:
Find -> 0.875*V
Substituted -> =0.875*V<TAB>=0.875*V<TAB>=0.875*V<TAB>
This regular expression already has worked us in Perl but I have not been able to figure out why it fails in Python.
From the results I can see the group is captured correctly but it is substituted with SOH character(Start Of Header) instead of captured value.
Our work environment:
- Windows 10 Pro
- Python 3.8
import re from pathlib import Path FILEHANDLER_R = open( "input.txt", "r" ) FILEHANDLER_W = open( "output.txt", "w" ) for line in FILEHANDLER_R: line = re.sub( "\t(\d*\.*\d*\**V*)", "\t=\1\t=\1\t=\1", line ) print( line ) FILEHANDLER_W.write( line ) FILEHANDLER_R.close() FILEHANDLER_W.close()Input file is:
Quote:vdd_0p9_hsio_ebipll 0.875*V 0.875*V 0.920*V 1.1*V 1.1*V 0.830*V 0.830*V 0.830*V 0.875*V
Output file results:
Output:vdd_0p9_hsio_ebipll = = = = = = = = = = = = = = = = = = = = = = = = = = =
Any ideas you can share with us is greatly appreciated.Thanks for the time reading this post.