Hallo Zusammen,
ich meine Problematik gelöst.
Code: Alles auswählen
shutil.copy(pathInput, pathOutput)
for line in fileinput.input(pathOutput, inplace=1):
# Step 1: Replace "Space" to ""
line = line.replace("$> $<", " ")
# Step 2: Replace "EXPD(" to "10**("
line = line.replace("EXPD(", "10**(")
sys.stdout.write(line)
# Step 3: Replace "LOG(" to "10**("
#Sollte eine Abfrage in der Datei starten, die die ganze Datei nochmal durchsucht
g = open(pathInput)
lineg = g.readlines()
global foundWord
stratLogSearch = 0
for iFor in lineg:
searchWord = lineg[stratLogSearch].find("LOG(")
if searchWord != -1:
lastRow = len(lineg[stratLogSearch])
lastComment = lineg[stratLogSearch].find("//")
if lastComment != -1:
lastSine = lastComment
else:
lastSine = lastRow
notRepWord = lineg[stratLogSearch][searchWord + 4:lastSine]
z = 1
y = len(notRepWord)
int(y)
w = 0
for iSearch in xrange(0, y):
w = w + 1
start = notRepWord[iSearch:iSearch + 1]
if start == "(":
z = z + 1
elif start == ")":
z = z - 1
if z == 0:
foundWord = notRepWord[:w - 1]
shutil.copy(pathInput, pathOutput)
for line in fileinput.input(pathOutput, inplace=1):
line = line.replace("LOG(" + foundWord + ")", "LN(" + foundWord + "/LN(10))")
sys.stdout.write(line)
break
stratLogSearch = stratLogSearch + 1
Aber einer Sache ist mir noch unklar. Die Funktion ersetzt nicht alle Beispiele.
Bsp.:
[codebox=text file=Unbenannt.txt]FUNCTION Ausnahme_Test: VOID
VAR_TEMP
myBool: BOOL;
x: STRING;
myByte: BYTE;
myReal: REAL;
END_VAR
BEGIN
myBool:=ENO;
x:='Test Test';
myByte:=PEEK_BYTE(AREA:=16#81,DBNUMBER:=0,BYTEOFFSET:=1);
myReal:=LOG((X)/(y));
myReal:=10**(2);
myReal:=LOG(X/(y));
%DB1.DBX1.0:=myBool;
myByte:=%IB1;
myReal:=LOG(X);
myReal:=LOG((X)/(y));
myReal:=LOG(X/(y));
myReal:=LOG(X/(y));(fg)
END_FUNCTION[/code]
Sieht jemand meinen Fehler warum nicht alle Beispiele ersetzt werden?
Mein Logger zeigt aber das alle Beispiele gesucht und versucht werden zu ersetzen.
BTW: Sry, das ist meine erste Python Erfahrung. Kann sein das man diese Funktion etwas effizienter machen kann.