YouTip LogoYouTip

Python3 File Readline

# Python3.x Python3 File readline() Method [![Image 3: Python3 File Methods](#) Python3 File Methods](#) * * * ### Overview The **readline()** method is used to read an entire line from a file, including the "n" character. If a non-negative integer argument is specified, it returns the specified number of bytes, including the "n" character. ### Syntax The syntax for the readline() method is as follows: fileObject.readline(); ### Parameters * **size** -- The number of bytes to read from the file. ### Return Value Returns the bytes read from the string. ### Example The following example demonstrates the use of the readline() method: The content of the file tutorial.txt is as follows: 1:www. 2:www. 3:www. 4:www. 5:www. Reading the content of the file: ## Example #!/usr/bin/python3 # Open the file fo =open("tutorial.txt","r+") print("The file name is: ", fo.name) line = fo.readline() print("Read the first line: %s" % (line)) line = fo.readline(5) print("The read string is: %s" % (line)) # Close the file fo.close() The output of the above example is: The file name is: tutorial.txt Read the first line: 1:www. The read string is: 2:www * * Python3 File Methods](#)
← Python3 File ReadlinePython3 File Fileno β†’