Saturday, 11 July 2026
Lecture 23 of 73 · Unit 1
Unit 1 ⏳ Pending
Unlocks at 05:00 PM, 11 Jul 2026

File basics, paths, modes, seek and tell Theory

What We'll Learn

A quick overview of today's lecture

File basics, paths, modes, seek and tell Theory Concept ID: U1_FILE_BASICS_MODES. Primary Sub-subtopic: File basics, paths, modes, seek and tell. Question-bank grouping: File Handling. Use this lecture for theory, examples, misconceptions, and short concept checks mapped to this concept ID.
Key things we'll cover
File basics, paths, modes, seek and tell
PYQ references used by both prompts 26 included 1 excluded
Flagged questions are excluded from both Study Notes and PPT references until corrected in Paper Analyzer.
Included ID 6475 · 2021 · 1 mark(s)
Which of the following option is not correct? a) if we try to read a text file that does not exist, an error occurs. b) if we try to read a text file that does not exist, the file gets created. c) if we try to write on a text file that does not exist, no error occurs. d) if we try to write on a text file that does not exist, the file gets created.
File Handling → File basics paths modes seek and tell
Included ID 6478 · 2021 · 1 mark(s)
A text file student.txt is stored in the storage device. Identify the correct option out of the following options to open the file in read mode. i. myfile = open('student.txt','rb') ii. myfile = open('student.txt','w') iii. myfile = open('student.txt','r') iv. myfile = open('student.txt') a) only i b) both i and iv c) both iii and iv d) both i and iii
File Handling → File basics paths modes seek and tell
Included ID 6483 · 2021 · 1 mark(s)
What is the significance of the tell() method? a) tells the path of file b) tells the current position of the file pointer within the file c) tells the end position within the file d) checks the existence of a file at the desired location
File Handling → File basics paths modes seek and tell
Included ID 6485 · 2021 · 1 mark(s)
Syntax of seek function in Python is myfile.seek(offset, reference_point) where myfile is the file object. What is the default value of reference_point? a) 0 b) 1 c) 2 d) 3
File Handling → File basics paths modes seek and tell
Included ID 6490 · 2021 · 1 mark(s)
Syntax for opening Student.csv file in write mode is myfile = open("Student.csv","w",newline=''). What is the importance of newline=''? a) A newline gets added to the file b) Empty string gets appended to the first line. c) Empty string gets appended to all lines. d) EOL translation is suppressed
File Handling → File basics paths modes seek and tell, CSV file read write and search
Included ID 6495 · 2021 · 1 mark(s)
Which of the following statement opens a binary file record.bin in write mode and writes data from a list lst1 = [1,2,3,4] on the binary file? a) with open('record.bin','wb') as myfile: pickle.dump(lst1,myfile) b) with open('record.bin','wb') as myfile: pickle.dump(myfile,lst1) c) with open('record.bin','wb+') as myfile: pickle.dump(myfile,lst1) d) with open('record.bin','ab') as myfile: pickle.dump(myfile,lst1)
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included ID 6518 · 2021 · 1 mark(s)
Consider the following directory structure. (Root: School → Subdirectories: Academics [contains Syllabus.jpg], Examination [contains Result.png], Sports [contains Achievement.jpg]) Suppose root directory (School) and present working directory are the same. What will be the absolute path of the file Syllabus.jpg? a) School/syllabus.jpg b) School/Academics/syllabus.jpg c) School/Academics/../syllabus.jpg d) School/Examination/syllabus.jpg
File Handling → File basics paths modes seek and tell
Included ID 6532 · 2022 · 1 mark(s)
Which of the following mode in file opening statement results or generates an error if the file does not exist? a) a+ b) r+ c) w+ d) None of the above
File Handling → File basics paths modes seek and tell
Included ID 6537 · 2022 · 1 mark(s)
The correct syntax of seek() is: a) file_object.seek(offset [, reference_point]) b) seek(offset [, reference_point]) c) seek(offset, file_object) d) seek.file_object(offset)
File Handling → File basics paths modes seek and tell
Included ID 6092 · 2023 · 1 mark(s)
Which of the following mode keeps the file offset position at the end of the file ? (a) r+ (b) x (c) w (d) a
File Handling → File basics paths modes seek and tell
Included ID 6097 · 2023 · 1 mark(s)
The syntax of seek( ) is file object.seek(offset[,reference point] ) What is the default value of reference point ? (a) 0 (b) 1 (c) 2 (d) 3
File Handling → File basics paths modes seek and tell
Included ID 6289 · 2023 · 1 mark(s)
Which of the following modes in Python creates a new file, if file does not exist and overwrites the content, if the file exists ? (a) r+ (b) r (c) w (d) a
File Handling → File basics paths modes seek and tell
Included ID 6294 · 2023 · 1 mark(s)
The correct syntax of tell() is: (a) tell.file object () (b) file object.tell() (c) tell.file object (1) (d) file object.tell1(1)
File Handling → File basics paths modes seek and tell
Included ID 6584 · 2023 · 1 mark(s)
Which of the following functions changes the position of file pointer and returns its new position? a) flush() b) tell() c) seek() d) offset()
File Handling → File basics paths modes seek and tell
Included ID 6313 · 2023 · 3 mark(s)
(a) Write a function in Python that displays the book names having 'Y' or 'y' in their name from a text file "Bookname.txt". Example : If the file 'Bookname.txt' contains the names of following books : One Hundred Years of Solitude The Diary of a Young Girl On the Road After execution, the output will be : One Hundred Years of Solitude The Diary of a Young Girl
File Handling → File basics paths modes seek and tell
Included ID 6600 · 2023 · 3 mark(s)
Write a function in Python to read a text file, Alpha.txt and displays those lines which begin with the word 'You'.
File Handling → File basics paths modes seek and tell
Excluded ID 6321 · 2023 · 5 mark(s)
(a) Write a point of difference between append (a) and write (w) modes in a text file. Write a program in Python that defines and calls the following user defined functions : (i) Add_Teacher() : It accepts the values from the user and inserts record of a teacher to a csv file "Teacher.csv". Each record consists of a list with field elements as T_id, Tname and desig to store teacher ID, teacher name and designation respectively. (ii) Search_Teacher() : To display the records of all the PGT (designation) teachers. (ii) Count_Device() : To count and display number of peripheral devices, whose price is less than or equal to 1000.
File Handling → CSV file read write and search
Awaiting categorisation review
Included ID 6322 · 2023 · 5 mark(s)
(b) Write one point of difference between seek() and tell() functions in file handling. Write a program in Python that defines and calls the following user defined functions : (i) Add_Device() : The function accepts and adds records of the peripheral devices to a csv file 'peripheral.csv'. Each record consists of a list with field elements as P_id, P_name and Price to store peripheral device ID, device name, and price respectively. (ii) Count_Device() : To count and display number of peripheral devices, whose price is less than or equal to 1000.
File Handling → File basics paths modes seek and tell, CSV file read write and search
Included ID 6607 · 2023 · 5 mark(s)
(i) Differentiate between r+ and w+ file modes in Python. (ii) Consider a file, SPORT.DAT, containing records of the following structure: [SportName, TeamName, No_Players] Write a function, copyData(), that reads contents from the file SPORT.DAT and copies the records with Sport name as "Basket Ball" to the file named BASKET.DAT. The function should return the total number of records copied to the file BASKET.DAT. (ii) A Binary file, CINEMA.DAT has the following structure: {MNO:[MNAME, MTYPE]} Where MNO – Movie Number, MNAME – Movie Name, MTYPE is Movie Type. Write a user defined function, findType(mtype), that accepts mtype as parameter and displays all the records from the binary file CINEMA.DAT, that have the value of Movie Type as mtype.
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included ID 6143 · 2024 · 1 mark(s)
Which of the following file opening mode is used to open a file in append and read mode ? (A) r+ (B) w+ (C) a+ (D) x+
File Handling → File basics paths modes seek and tell, Text file reading writing searching and counting
Included ID 6161 · 2024 · 3 mark(s)
Write the user defined function Modify() to read a text file "data.txt" and replace all the occurrences of "COmputer" with "Computer" and display all the lines on screen.
File Handling → File basics paths modes seek and tell
Included ID 6365 · 2024 · 5 mark(s)
(a) (i) What is the main purpose of seek() and tell() method ? (ii) Consider a binary file, Cinema.dat containing information in the following structure : [Mno, Mname, Mtype] Write a function, search_copy(), that reads the content from the file Cinema.dat and copies all the details of the "Comedy" movie type to file named movie.dat. (ii) A Binary file, "Items.dat" has the following structure : [Icode, Description, Price] Where Icode – Item code Description – Detail of item Price – Price of item Write a function Add_data(), that takes Icode, Description and Price from the user and writes the information in the binary file "Items.dat".
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included ID 6192 · 2025 · 1 mark(s)
Assertion (A): For a binary file opened using 'rb' mode, the pickle.dump() method will display an error. Reason (R): The pickle.dump() method is used to read from a binary file. (A) Both Assertion (A) and Reason (R) are true and Reason (R) is the correct explanation for Assertion (A). (B) Both Assertion (A) and Reason (R) are true and Reason (R) is not the correct explanation for Assertion (A). (C) Assertion (A) is true but Reason (R) is false. (D) Assertion (A) is false but Reason (R) is true.
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
Included ID 6405 · 2025 · 3 mark(s)
(a) Write a Python function that displays all the lines ending with a dot (.) from a text file, "Colors.txt". For example, if the file "Colors.txt" contains : White is a mix of seven colors. What are these seven colors ? VIBGYOR – violet, indigo, blue, green, orange and red. When we mix all these colors we just get one light which is the WHITE light. Then the output should be : White is a mix of seven colors. VIBGYOR – violet, indigo, blue, green, orange and red. which is the WHITE light. (Hint : You will have to ignore trailing white spaces to check the last character)
File Handling → File basics paths modes seek and tell
Included ID 6694 · 2025 · 3 mark(s)
A. Write a Python function that displays the number of times the word "Python" appears in a text file named "Prog.txt".
File Handling → Text file reading writing searching and counting
Included ID 6217 · 2025 · 4 mark(s)
Write a program in Python to create a text file MARKS.TXT and write the names of all those students and their total marks obtained in Physics, Chemistry and Maths whose total marks are greater than 220.
File Handling → File basics paths modes seek and tell
Included ID 6227 · 2026 · 1 mark(s)
Consider the statement given below : f1 = open("pqr.dat","_______") Which of the following is the correct file mode to open the file in read only mode ? (A) a (B) rb (C) r+ (D) rb+
File Handling → File basics paths modes seek and tell, Binary file operations with pickle
.txt