File Handling

  1. Text Files

    Question 1 of 3

    • Create a text file python.txt on your desktop and write short essay about python on it.
    • Open this file python.txt. Add text I will learn Error Handling Next at end
    • Create a new file java.txt. Copy the content of python.txt to java.txt but replacing the text python with java.
    • Calculate and display the size of python.txt and java.txt in KB. (Hint: use os module & AI)
    • Read file nobel_prize_speech.txt and display most repeated word on it.
  2. CSV Files

    Question 2 of 3

    • Create a csv file std_1.csv with columns: Name, Age, Grade. Add 5 records to it using list of list.
    • Create a csv file std2.csv with columns: Name, Age, Grade. Add 5 records to it using list of dict.
    • Read file 2022-01-03.csv and display records as list of list.
    • Read file 2022-01-03.csv and display records as list of dict.
  3. JSON File

    Question 3 of 3

    • Store 5 students data in dict as {"9843": {"name": "Rabindra", "age": 30, "course": "Python"}, "9844": {"name": "Hari", "age": 25, "course": "Java"}....}. Save this data in file info.json.
    • Load info.json file. Convert the data in list of dictionary like [{"phone": "9843", "name": "Rabindra", "age": 30, "course": "Python"}, ....]. Save coverted data in info.csv file.
    • Read file election_result.json. Find name of winner, associated party and votes obtained
    • Read file election_result.json. Find total vote casted and average vote per candidate.
    • Convert the file election_result.json in csv format and save it as election_result.csv.