hello this is btechgeeks

good morning btechgeeks

Example3: passing size as an argument

Approach:

  • Make a single variable to store the path of the file. This is a constant value. This value must be replaced with the file path from your own system in the example below.
  • Open the file in read mode. In this case, we’re simply reading the contents of the file.
  • Pass some random number(size) to the readline() function to get the given number of bytes from the file and print the result.
  • The Exit of Program.

Below is the implementation:

# Make a single variable to store the path of the file. This is a constant value.
# This value must be replaced with the file path from your own system in the example below.
givenFilename = "samplefile.txt"
# Open the file in read mode. In this case, we're simply reading the contents of the file.
gvn_file = open(givenFilename, 'r') 
# Pass some random number(size) to the readline() function to get the given number of bytes from the
# file and print the result
print(gvn_file.readline(10))

Output:

hello this