Monday, 18 November 2024

Write a python program to accept a file name from the user and perform operations.



Q. What is Data Streaming and Buffering?

Data Streaming and Data Buffering is nothing but different methods of data transfer among client server architecture. As we know with HTTP Protocol, the client can either transfer data to the server that is uploading data to the server or sometimes client request some data from the server means downloading data from the server.


When the size of the data is more than some Megabytes to ensure the loss of data is minimal client and server can choose to transfer data in different chunks.


Now, when the server selects to send the data in chunks. so, at the time of download operations server chooses to transfer data in different chunks.

Now, when the client selects to send the data in chunks. so, at the time of uploading operations client choose to transfer data in different chunks.

Q. What is data Buffering?

Ans: When the requested data is completely accumulated inside the memory and then processed, we called it Buffering.


Q. What is Data Streaming?

Ans: when the data is processed at the time each chunk is received, we called it Streaming.

This is possible because request implements Readable Stream interface, and the content can be directly written to the file system using Writable Stream interface.

Q. What is File?

A File is collection of data that is stored on various devices like Computer, Laptop, Mobile and Servers.
We can say that file is the fundamental unit of digital storage which is used to Store, organize and manage data permanently on secondary storage.

Q. Why do we require File in python?

A File is collection of data that is stored on various devices like Computer, Laptop, Mobile and Servers. Now just consider the following scenario in python.

1. We write a python program to store employee information.
2. Accordingly, we write one class of employee.
3. We have created Three objects of employee inside the RAM (Random Access Memory) and store all the data inside it for three employees. but as you know RAM is a volatile memory that data is available till power is on.
4. Once power is off all data vanished from RAM and we loss all data completely.
5. Now every time when we want that data, we have to execute the code and create data inside the RAM.
6. What if we want that data permanently get stored inside secondary storage so that we can access it whenever we want. To accomplished these, we have to create a file and write all data inside that file for permanently storage.
7. Below is the scenario of Program RAM and File.


Q. How to create File in python?

By using python inbuilt function open (filename, mode) we can create file in python.



How many modes file gets open in python?

  1. r: open for read operation but file must be present.
  2. w: open already existed file if present and override the content in it. but if file is not already present in that case it can create new file and write in it.
  3. a: open already present file in append mode. in this mode we append content at the end.
  4. r+: To perform both operation (read and write data into the file). This mode does not override the already present data, but you can change the data starting from the beginning of the file.
  5. w+: To perform both operation (write and read data). It overwrites the previous file if it is already present, it will truncate the file to zero length or create a file if it does not exist.
  6. a+: To append and read data from the file. It will not override already present data.

Problem Statement:

Write a python program to accept a file name from the user and perform the following operations as       

1. Display the first N line of the file 
2.Find the frequency of occurrence of the word accepted from the user in the file





The number of functions used in above code and their usage are as follows:

1. Strip() Function: If no character is specified in Strip() function then by default it removes all the starting and ending whitespaces.

For Example:

Case 1:

msg = "  JSPM UNI  "

afterstriped = msg . strip ()

print(afterstriped)  # output is: "JSPM UNI"

Case 2:

msg = " ....,,,,nmsssss good sssrrt,,,...st"

afterstrip = msg . strip(".,nmsrt")

print(afterstrip) #output is: good





data structures and algorithms Web Developer

No comments:

Post a Comment