How to check file existence using Python?

Small tutorial with code examples and video about how to check if file exists in Python
10 August 2017   1713

There are several Python methods to check does a file exist.

1. os.path.isfile
It returns True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be true for the same path.

import os.path
os.path.isfile(fname)

if you need to be sure it's a file.

2. Starting with Python 3.4, the pathlib module offers an object-oriented approach (backported to pathlib2 in Python 2.7):

from pathlib import Path

my_file = Path("/path/to/file")
if my_file.is_file():
    # file exists

3. To check a directory, use:

if my_file.is_dir():
    # directory exists

4. To check whether a Path object exists independently of whether is it a file or directory, use exists():

if my_file.exists():
    # path exists

You can also use resolve() in a try block:

try:
    my_abs_path = my_file.resolve():
except FileNotFoundError:
    # doesn't exist
else:
    # exists

Google to Release Cloud Inference API

Cloud Inference API can be used for real time big data analysis 
20 September 2018   119

Google introduced an alpha version of the service for time series analysis. It processes information about events at the time - clicks, requests, activations of IoT devices, and so on. The Cloud Inference API analyzes these data in real time, finds correlations and makes predictions based on it.

Cloud Inference API
Cloud Inference API 

Service features:

  • A simple tree-like query language that allows you to specify your own time markers.
  • Online processing of incoming data with minimal delay. Therefore, Google recommends using the API in interactive user applications.
  • Ability to process data arrays of different volumes (up to trillions of records) and work under high load (up to hundreds of thousands of requests per second).
  • Full integration with Google Cloud Storage, which provides access to the same data in different services of the platform.
  • More information about the work of the tool can be found in the documentation.

Google noted that the service will be useful for a wide range of industries. Retailers can analyze the impact of pedestrian traffic on the level of sales conversion, content providers - the popularity of materials to provide better personal recommendations.

Now the Cloud Inference API is already being used by Snap to analyze the data received through the Snapchat application.

Google Cloud is developing a number of cloud services. At the end of August 2018, the company updated the tools for converting speech to text and vice versa. Cloud Text-to-Speech received support for several new languages ​​and voices, and Cloud Speech-to-Text - recognition of several speakers, language and the ability to highlight important words