Featured Post

The Quick and Easy Way to Analyze Numpy Arrays

The quickest and easiest way to analyze NumPy arrays is by using the numpy.array() method. This method allows you to quickly and easily analyze the values contained in a numpy array. This method can also be used to find the sum, mean, standard deviation, max, min, and other useful analysis of the value contained within a numpy array. Sum You can find the sum of Numpy arrays using the np.sum() function.  For example:  import numpy as np  a = np.array([1,2,3,4,5])  b = np.array([6,7,8,9,10])  result = np.sum([a,b])  print(result)  # Output will be 55 Mean You can find the mean of a Numpy array using the np.mean() function. This function takes in an array as an argument and returns the mean of all the values in the array.  For example, the mean of a Numpy array of [1,2,3,4,5] would be  result = np.mean([1,2,3,4,5])  print(result)  #Output: 3.0 Standard Deviation To find the standard deviation of a Numpy array, you can use the NumPy std() function. This function takes in an array as a par

6 Python file Methods Real Usage

Files always have data in them. For different purposes, you need methods to deal with them. These six file methods of use in this case.

Related: 5 top file modes in python.

Python file methods

Python file methods

Below are the top six file methods in python:
  1. Tell()
  2. Seek()
  3. Flush()
  4. Fileno()
  5. truncate()
  6. isatty()

1. tell()

The usage of tell method is it returns the cursor-position of the file-pointer from the beginning of the file. It tells the current cursor position. The position starts from zero, which is same as of an index.



2. seek()

The usage of seek method is cursor position, from one position to the specified position from the beginning of the file, it moves. Here, the cursor will be sought to a particular location.



3. flush()

The usage of flush method is clean out the internal buffer. Before writing the text in the file, it is best practice to clear out that the internal buffer can be cleared.



4. fileno()

The usage of  fileno method is file-number i.e. a file descriptor as an integer value it returns. If an operating system does not use a file descriptor of the file then an error may occur.



5. truncate()

The usage of truncate method is on the given number of bytes it resizes the file. The current position will be used if the size is not specified.



6. isatty()

The usage of isatty method is Boolean. True if the file is connected to an end device like (tty) device else will return False.





Popular posts from this blog

How to Decode TLV Quickly

7 AWS Interview Questions asked in Infosys, TCS