in Education by
import os import sys import fileinput print ("Text to search for:") textToSearch = input( "> " ) print ("Text to replace it with:") textToReplace = input( "> " ) print ("File to perform Search-Replace on:") fileToSearch = input( "> " ) #fileToSearch = 'D:\dummy1.txt' tempFile = open( fileToSearch, 'r+' , encoding="utf8") for line in fileinput.input( fileToSearch ): if textToSearch in line : print('Match Found') else: print('Match Not Found!!') tempFile.write( line.replace( textToSearch, textToReplace ) ) tempFile.close() input( '\n\n Press Enter to exit...' ) 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
Looks like you're opening a binary file (if so, save it as a plain text), or a file with not matching encoding (utf-8). If you need to work with docx document, you need some specialized library for opening and reading, for example python-docx.

Related questions

0 votes
    I need to use environment variable "PATH" in yaml file which needs to be parsed with a script. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 10, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    What happens if ServerSocket is not able to listen on the specified port? (a) The system exits gracefully with ... & Servlet of Java Select the correct answer from above options...
asked Feb 22, 2022 in Education by JackTerrance
0 votes
0 votes
    1. Write a function in python to read the content from a text file “poem.txt” line by line and display the same on screen Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    I have a big data frame. I want to replace float 1.0 and 0.0 with the true and false. My code: import pandas ... to do it in one line. Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Is there any way to get to know that a link is download-able? means the link represent any audio, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    ___________ function is used to apply an expression for a given dataset. (a) This() (b) With() (c) ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    I have the function and want to create a new column df['growth_factor'] which will have a derived value in it. ... can I achieve this? Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    What is the function of ‘git stash apply’?...
asked Nov 2, 2020 in Technology by JackTerrance
0 votes
    I am writing data to a file using an ObjectOutputStream. I have a class Data which implements Serializable ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 2, 2022 in Education by JackTerrance
0 votes
    _________ is a powerful input component which holds the ability to replace a number of other ... of the File family. tFileInputLDIF tFileInputRegex tFileInputExcel tFileInputJSON...
asked Mar 25, 2021 in Technology by JackTerrance
0 votes
    When I'm extending my UIViewController and calling the extended ViewController I'm getting : Terminating app due ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    After reading up on some options (sqlite, derby etc...), I've decided to throw down with HSQLDB. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    Select * from OPENQUERY (PORTAL, ''SELECT st.last AS "Last Name", st.first AS "First Name", ct. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
...