How to call an external command in Python?

Five ways to call external command in Python with code examples and video 
10 August 2017   1766

Hype.Codes team have found several ways to solve this issue.

1. Using subprocess module in the standard library:

from subprocess import call
call(["ls", "-l"])

The advantage of subprocess vs system is that it is more flexible.

The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function [os.system()].

2. os.system("some_command with args") passes the command and arguments to your system's shell. This is nice because you can actually run multiple commands at once in this manner and set up pipes and input/output redirection. For example:

os.system("some_command < input_file | another_command > output_file")

However, while this is convenient, you have to manually handle the escaping of shell characters such as spaces, etc. On the other hand, this also lets you run commands which are simply shell commands and not actually external programs.

3. stream = os.popen("some_command with args") will do the same thing as os.systemexcept that it gives you a file-like object that you can use to access standard input/output for that process. There are 3 other variants of popen that all handle the i/o slightly differently. If you pass everything as a string, then your command is passed to the shell; if you pass them as a list then you don't need to worry about escaping anything.

4. The call function from the subprocess module. This is basically just like the Popen class and takes all of the same arguments, but it simply waits until the command completes and gives you the return code. For example:

return_code = subprocess.call("echo Hello World", shell=True)  

5. If you're on Python 3.5 or later, you can use the new subprocess.run function, which is a lot like the above but even more flexible and returns a CompletedProcess object when the command finishes executing.

Google to Release Cloud Inference API

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

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