File handling in Python

We can read , write ,append or create file by using file handler object in Python. Here are the methods we will be using for managing files.

Python file handling methods with different modes to read write & append data in text & binary mode

read()Reading content of a file
readable()Check if file is readable or not
write()Write content to file
seek()Move the file pointer to different location inside the file
seekable()Check if file is seekable or not
tell()Get the position of the file pointer
readlines()Getting a list from the content of a file
readline()Reading line of data from a file
truncate()Resize a file upto the input bytes
writable()Check if the file is writable or not
writelines()Writing list to file

Reading CSV file

We can use one Comma Separated Values( CSV ) file and use one of the column as options for a combobox.
Download the sample student CSV file from here

We used append method to add elements to the list.
path="D:\\my_data\\student.csv" # sample CSV file, use your path
headings = next(fob) # removing header row
for rec in fob:
  names.append(student[1]) # name added
Read the practice question with solution on how to create csv file using
user inputs and then creating dictionary by reading data from the csv file.
Finally use the dictionary to create csv file.

File Append File Write


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 All rights reserved worldwide Privacy Policy Disclaimer