Sep-03-2023, 10:22 PM
(Sep-03-2023, 05:43 PM)Skaperen Wrote: you have code or you intend to have code. if you have learned enough you can at least try to make code. if you show us what you have tried (even if it immediately fails) we might get some idea of what you are thinking or what you need to change so it goes on to the next step.
i do not understand your description of what you are trying to do.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import csv def nsplit(nstring, delimiter): slist = [delimiter + word.strip() for word in nstring.split(delimiter) if word] return slist def replace_text(strin, replace_this, with_this): nlist = nsplit(strin, '-' ) for row, item in enumerate (nlist): if replace_this in item: itemx = item.split( ' ' ) nitem = f "{with_this} {itemx[1]} " nlist[row] = nitem nstr = ''.join(nlist) return (nstr) def testit(): csv_file_path = '/Users/ecosta/Downloads/gtp_timers_ericsson_nokia.csv' buf = "-nrrc 3 -trac 3 -nrds 2 -trds 5 -nrcs 2 -nrmb 2 -trmb 2 -nrrab 2 " \ "-trrab 1-nri 3 -tri 3 -nrfr 2 -trfr 7 -nfrc 2 -tfrc 1 -nfac 2 " \ "-tfac 1 -nrca 2 -trca 1 -nrdbc 2 -trdbc 4 -nrmbc 2 -trmbc 4 -era on " \ "-nre 5 -tre 120 -trsl 24 -nrcn 1 -trcn 4 -nrpc 2 -trpc 7 -tnsc 10 " \ "-nns 2 -tas 1 -nnr 2 -tar 1 -nnsc 2 -tasc 1 -pb off -sncr off " \ "-trer 1 -eras off -nres 3 -tres 3000 -eris 60 -trcs 5000 -eriss 60 " \ "-nress 3 -tress 3 -eram off -erim 60 -nrem 3 -trem 3 -trgl 1 " \ "-trcss 4000 -trdss 2 -trmbs 2 -trmbcs 4 -nrcss 2 -nrdss 3 -nrmbs 2 " \ "-nrmbcs 2 -mmbr off -mabr on -nrmab 2 -trmab 2 -trml 24 -nbsig on " \ "-rnccpe true -rnccsi true -dnd 0 -hfipe false -nrcit 2 -trcit 2 " \ "-nrdit 2 -trdit 2 -tdit 6 -tavac 2 -scn false -nrbrc 2 -nrbrcs 2 " \ "-trbrc 4000 -trbrcs 4000 -gpfcl 72,73,78,83,84,86,91,100,113,120 " \ "-rlm off -atrc 10 -sots off" with open (csv_file_path, 'r' ) as file : csv_reader = csv.reader( file ) data_list = [] for row in csv_reader: data_list.append(row) for row in data_list: newstring = replace_text(buf, replace_this = row[ 0 ], with_this = row[ 1 ]) print (newstring) if __name__ = = '__main__' : testit() |