Ciao, per prima cosa opererei riga per riga, quindi:
##################################################################### file = open(fileName, "r") #Opens the file in read-mode filelist = file.readlines() #Creates a list called filelist. This list has two member, #each of which is an argument that has to be passed to the gconftool-2 --set command file.close() #Close the file for fileline in filelist: *qui le istruzioni per processare le singole righe* ###################################################################### poi per estrarre l'intervallo di caratteri fra ":" e "AB" ti potrebbe bastare qualcosa come fileline = fileline[8:13] poi converti fileline da stringa a numero e moltiplichi per 11. per la sostituzione usa questa funzione: ########################################################################### def replacemachine(fileName, sourceText, replaceText): ########################################################################################### file = open(fileName, "r") #Opens the file in read-mode # text = file.read() #Reads the file and assigns the value to a variable # file.close() #Closes the file (read session) # file = open(fileName, "w") #Opens the file again, this time in write-mode # file.write(text.replace(sourceText, replaceText)) #replaces all instances of our keyword # # and writes the whole output when done, wiping over the old contents of the file # file.close() #Closes the file (write session) # ########################################################################################### che invochi con: fileName = "tuofile.txt" sourceText = "AB" replaceText = "RB" replacemachine (fileName, sourceText, replaceText) Ciao! Il giorno 25 gennaio 2010 15.20, Lorenzo Macchiavelli < lmacchiave...@gmail.com> ha scritto: > Salve a tutti qualcuno può aiutarmi?? > Dovrei fare un find and replace in py un pò avanzato("" Per ME!!!"") > > del tipo: Quando è presente la stringa di tipo "AB" Devo Sostituire i > valori all'intero tra i " : " e " AB " moltiplicando per 11 > il valore all'interno e sostituire la stringa "AB" CON "RB". > > Il File è formattato in questo modo: > ... > RTS_YAS:10293AB > RTC_YAS:1003AB > RTS_YAS:010003RB > ... > > ESEMPIO: " RTS_YAS:10293AB " diventa "RTS_YAS:113223RB" > > Qualcuno può spiegarmi come fare??? quale ragionamento fareste per > risolvere questo tipo di problema?? > So che magari può sembrare banale... ma sto cercando di capire > quale tipo di approccio userebbe un programmatore esperto!! > > Grazie Anticipatamente > > Lorenzo Macchiavelli > > _______________________________________________ > Python mailing list > Python@lists.python.it > http://lists.python.it/mailman/listinfo/python > >
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python