Showing posts with label file handling function in python. Show all posts
Showing posts with label file handling function in python. Show all posts

Friday, May 29, 2020

,

python built-in function for file handling

Python File Method : - 

These all are the python built-in function which is used to manipulate the python files and update these files in python.

python built-in function for file handling
python built-in function for file handling

close() method in python : - 

close() method in python closes an open file. A file should always be closed because without closing file changes made to a file may not show until you close the file.

Syntax : -

file.close() 

Python File fileno() Method : - 

fileno() function in python returns the file descriptor of the stream, as a number, and an error will occur if the operating system does not use a file descriptor.

Syntax : -

file.fileno()
 

Python flush() Method : - 

flush() function solve the buffer problem this function  cleans out the internal buffer.

Syntax : -

file.fileno()

isatty() function in python : - 

isatty() function in python returns True if the file stream is interactive, example: connected to a terminal.

Syntax : -

file.isatty()

read() function in python : - 

read() method in python gives the number of bytes of the specified file, Default is -1 it means the whole file.

Syntax : -

file.read()

readable() function in python : - 

readable() function in python gives true if the file is readable,or false if the file is not readable.

Syntax : -

file.readable()

readline() function in python : - 

readline() in python returns one line from the file. The programmer can also decide how many bytes from the line to return.

Syntax : -

file.readline(size)

readlines() method in python : - 

readlines() method in python gives a list that contains each line in the file as a list item. You can use the hint parameter to limit the number of lines returned.

Syntax : -

file.readlines(hint)

seek() method in python : - 

seek() method in python set the current file position in a file stream and return the new position of the file.

Syntax : -

file.seek(offset)

seekable() method in python : - 

seekable() in python method returns True if the file is seekable, False if not. A file is seekable if it allows access to the file stream in python.

Syntax : -

file.seekable()

tell() function in python : - 

tell() method in python gives the current file position in a file stream and the file position can be changed with the help of seeks function in python.

Syntax : -

file.tell()

truncate() function in python : - 

truncate() method in python use to resize the file to the given number of bytes.
 If the size is not specified, the current position will be used.

Syntax : -

file.truncate(size)

writable() function in python : - 

writable() method in python gives true if a file is writable and a file is writable so it is opened using "a" for append or "w" for write.

Syntax : -

file.writable()

Python File write() Method

write method in python is used to write specified text into the file.

Where this text will be inserted depends on the file mode and stream position.

"a":  The text will be inserted at the current file stream position, default at the end of the file.

"w": The file will be emptied before the text will be inserted at the current file stream position, and the default will be 0. 

Syntax : -

file.write(byte)

writelines() Method

writelines() function in python writes the items of a list into the specified file.

Where this item will be inserted depends on the file mode and stream position.

"a":  The item will be inserted at the current file stream position, default at the end of the file.

"w": The file will be emptied before the list item will be inserted at the current file stream position, and the default will be 0.

Syntax : -

file.writelines(list)