Week 12: Python

Python is en route to becoming the most widely used programming language of the 21st century. Hobbyists love it, analysts love it, and even kids starting to code use Python these days.

  • PDF / 881,669 Bytes
  • 24 Pages / 439.37 x 666.142 pts Page_size
  • 25 Downloads / 177 Views

DOWNLOAD

REPORT


Week 12: Python Always look on the bright side of life. —Monty Python

Python is en route to becoming the most widely used programming language of the 21st century. Hobbyists love it, analysts love it, and even kids starting to code use Python these days. With its simple syntax and zillions of available libraries, you can’t go wrong with Python. Recently, many of these libraries have refocused on machine learning, AI, data science…so much so that Python, the language, does not require much of an introduction. That said, here’s one (Figure 12-­1).

Figure 12-1.  Hello, Python

© Nicolas Modrzyk 2019 N. Modrzyk, Building Telegram Bots, https://doi.org/10.1007/978-1-4842-4197-4_12

247

Chapter 12

Week 12: Python

While I also like Python, a lot of the code is easy to write but harder to maintain. So, I usually switch to another language, but it’s hard to match the number of libraries available with Python—OpenCV, TensorFlow…all come with a first-class Python wrapper.

Installation 3.6. What is it? 3.6 is the version of Python you want to install. Yes, the latest version is 3.7, but the TensorFlow library did not support version 3.7 at the time of writing, so you are better off using 3.6. If you really do not care about the TensorFlow samples, but I hope you do, you can stick to 3.7. Python itself sometimes comes preinstalled and is already available. If not, or if the version does not match, or if you’re a Windows lover, you can download the installer from the following Python download page: https://www.python.org/downloads/windows/ The Python package manager, pip, will have to be installed as well. You can perform the installation for that by following the steps here. https://pip.pypa.io/en/stable/installing/ Or, in short, # download the get-pip.py file( manually if you don't have curl) curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py # execute it with the python executable python get-pip.py An alternative but recommended method is to install mode for Python and use a tool named pyenv. pyenv is a small tool that allows you to switch from one Python tree to another, meaning you can switch from one version of Python and its libraries to another. https://github.com/pyenv/pyenv#installation

248

Chapter 12

Week 12: Python

With pyenv installed, you can now switch from one version of Python to another in a convenient manner. To check the versions installed, use pyenv versions. $ pyenv versions   system * 3.6.0 (set by /Users/niko/.pyenv/version)   3.7.0   anaconda3-5.0.1 As shown in the preceding and following code snippets, we’re supporting Python version 3.6 and pip version 18.0. Yes, 3.6, because, again, the TensorFlow packages were not available for Python 3.7 at the time of writing. $ pip --version pip 18.0 from /Users/niko/.pyenv/versions/3.7.0/lib/python3.7/ site-packages/pip (python 3.7) But python2 is also perfectly usable, but not much tested in the scope of this book. In a new folder for the forthcoming Python script, we can set up the tasks.json usable by Visual Studio Code. {     "version": "2.0