Python Working with Files

Python Working with Files
Python Working with Files

Pre Quiz – Working with Files


Q1 – Name the python module that supports regular expressions.




Q2 – Describe the function re.match.
Select one:




Q3 – Describe the function re.search.
Select one:




Q4 – Analyse and predict the output of the following code.

python code
python code



Q5 – Analyse and predict the output of the following

python code
python code




Practise Session – Working with Files


Q1 – Open the le ‘odi.csv’ using DictReader in read mode and store it in the variable reader. (Use single quotes)

reader=csv.DictReader(open(‘odi.csv’,’r’))


Q2 – Fill the code to open the text le data_science in read mode using with statement and to print all the statements within the le.(Use single quotes)/h3>

with open(‘data_science.txt’,’r’)

as f:
print(f.

readlines()

)



Post Quiz – Working with Files


Q1 – Select the correct built-in function(s) to read a line of text from standard input, which by default comes from the keyboard




Q2 – “You can read all the lines in the text le using .readlines() function”. State True or False.




Q3 – “We can open a le in “a” mode to append text towards the end of the le”. State True or False.




Q4 – Select the correct option(s) that describe(s) “pickling” in Python.
Select one:




Q5 – “When we use DictReader for reading small csv les, each line in the le is read as dictionary and columns in the data will be available as keys of the dictionary”. State True or False.





Check Your Understanding_ Attempt_Files


Q1 – We know that DictReader() is used to read data from a CSV. What does this method return ?

List of Dictionaries


Q2 – Match the following
readline()

returns a single line from file

read()

returns the entire file

readlines()

returns a list containing all lines of the file


Q3 – Every line of a text le is terminated with End of Line character. State true or false.




Q4 – The process of conversion of Python object hierarchy into a byte stream is called as

Pickling

and the inverse operation, whereby a byte stream is converted back into an object hierarchy is called as

Unpickling


Q13 – Which of the following statements are true with respect to the with statement ?




Recommended :-

  1. Store Student Data
  2. Read CSV file
  3. Filter countries Sachin has played against
  4. Calculate year-wise total number of runs of Sachin

Leave a Comment

Your email address will not be published. Required fields are marked *

x