in Education by
arr = [(line.rstrip('\n').split(';')) for line in open('C:/Config_Changer.csv')] import sys import fileinput for i, line in enumerate(fileinput.input('C:/1.cfg', inplace = 1)): sys.stdout.write(line.replace(arr[0][0], arr[0][1])) Hey all, I wrote the above lines so it's working fine but its replacing only ary[0][0], so i want to loop it as like below,so first dimention is needed to loop.Can anyone help me with the loop commands.Where should I have to put loop exactly ??? sys.stdout.write(line.replace(arr[a][0], arr[a][1])) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
so what you want is to apply all the replacements that are in arr to the line: (unlike aix's answer, this one avoids the explicit indexing) for i, line in enumerate(fileinput.input('C:/1.cfg', inplace = 1)): for f,t in arr: line = line.replace(f, t) sys.stdout.write(line)

Related questions

0 votes
    arr = [(line.rstrip('\n').split(';')) for line in open('C:/Config_Changer.csv')] import ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    arr = [(line.rstrip('\n').split(';')) for line in open('C:/Config_Changer.csv')] import ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I try to print images with a for loop but the images dont load. The images are in the same ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 10, 2022 in Education by JackTerrance
0 votes
    Which is the function used to loop in an array to view all the values? (a) all() (b) loop( ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    Which is the function used to loop in an array to view all the values? (a) all() (b) loop() (c) ... Questions for GATE EC Exam, Network Theory MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    I am trying to open a zip file and iterate through the PDFs in the zip file. I want to scrape a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I want to save files for each result from the loop. For example, I wrote the code but it only saves one file ... do I modify my code? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    How do I use the for loop to execute the following operation? df_1=pd.concat([df_ab1,df_xy1], axis=1) df_2= ... Am I missing something? Select the correct answer from above options...
asked Jan 10, 2022 in Education by JackTerrance
0 votes
    If I use a while loop for my below code, it is not giving the desired output, but when i use for loop i am anle ... x += 1 print(Comm) Select the correct answer from above options...
asked Jan 9, 2022 in Education by JackTerrance
0 votes
    infinite for loop PYTHON Select the correct answer from above options...
asked Nov 30, 2021 in Education by JackTerrance
0 votes
    This question already has answers here: Concatenate two NumPy arrays vertically (4 answers) Closed 3 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Concatenate two NumPy arrays vertically (4 answers) Closed 3 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Concatenate two NumPy arrays vertically (4 answers) Closed 3 years ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    What is the problem Here ? I got an error shows ValueError: too many values to unpack This code ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...