Site icon KSoftLabs

File Handling

Python Tutorial by KSoftLabs.com

Opening a file

thefile=open("sample.txt","r")

Here we are creating a file object name “thefile” and assigning the data in the “sample.txt” to it. The “r” parameter says that the file is opened as read-only.

Other arguments are:

Reading a file

thefile.read(10)

This code will read the first 10 bytes of the file object “thefile”. If you haven’t define the number of bytes to be read, Python will try to read as much as possible.

 

 

 


The owner of  www.ksoftlabs.com will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
This terms and conditions are subject to change at anytime with or without notice.

Exit mobile version