In: Computer Science
By only importing multiprocessing
Write a python program which do the following :
1- Create one process this process must-read the content of a file “read any file content exist in your machine” and after that create another process in the first process function which will get the file content as a parameter for the second process function.
2- The second process function will get the file content and check out if there are any special characters or numbers in the text, if the condition is true then delete all special characters or numbers otherwise find out the number of words and characters in that content.
from multiprocessing import Process
def secondProcess(data):             //Second process function
    spCharsList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9','@', '_', '!', '#', '$', '%', '^', '&', '*', '(', ')', '<', '>', '?', '/', '|', '}', '{', '~', ':', ';']
    setFlag = 0
    newdata = ''
    size = len(data)
    for i in range(0, size):
        if data[i] in spCharsList:
            setFlag = 1
        else:
            newdata += data[i]
            continue
    
    numChar = 0
    numWord = 0
    if setFlag == 0:
        
        numChar = len(newdata)
        numWord = len(newdata.split(' '))
        print("Number of words in file Content : ", numWord)
        print("Number of characters in file Content : ", numChar)
    else:
        print("File contents BEFORE removing special characters : \n")
        print(data)
        print("File contents AFTER removing special characters : \n")
        print(newdata)
    
def firstProcess():                       //first process function
    fopen = open("hello.txt", "r")
    data = fopen.read()
    data = data.replace('\n', ' ')        //Replacing new line char with space
    fopen.close()
    fS = Process(target = secondProcess, args = (data, )) //creting second process
    fS.start()                                            //starting second process
    fS.join()                                             //waiting for second process to finish
    
fP = Process(target = firstProcess)               //Creating first process
fP.start()                                        //Starting first Process    
fP.join()                                         //Waiting for first process to fininsh