Page 154 - PYTHON-12
P. 154

10.  Write a statement to open a binary file C:\Myfiles\Text1.txt in read and write mode by specifying for file
                   path in two different formats.
                11.  What are the advantages of saving data in : (i) binary form (ii) text form ?
                12.  When do you think text files should be preferred over binary files?
                13.  Write a statement in Python to perform the following operations:            [CBSE D 2016]
                    (a)  To open a text file "BOOK.TXT" in read mode
                    (b)  To open a text file "BOOK.TXT" in write mode
                14.  What is following code doing?

                     File = open("contacts.csv", "a")
                     Name = input("Please enter name: ")
                     Phno = input("Please enter phone number: ")
                     File.write(name + ", " + phno + "\n")
                15.  Write code to open the file in the previous question and print it in the following form:
                      Name : <name>   Phone: <phone number>
                16.  Consider the file "contacts.csv" created in above Q and figure out what the following code is trying to do?
                       name = input("Enter name:")
                       file = open("contacts.csv", "r")
                       for line in file:
                           if name in line:
                               print(line)
                    Create a CSV file "Groceries" to store information of different items existing in a shop. The information is
                   to be stored w.r.t. each item code, name, price, qty. Write a program to accept the data from user and
                   store it permanently in CSV file.




































                                                                                                                  Python Libraries







                                                                                                            4.25
   149   150   151   152   153   154   155   156   157   158   159