Python 3.6 on Windows ... and to Xamarin.

* A memorandum written by a Python beginner with delusions because I understood a little about the future possibilities of Python 3.6 type annotation. </ font>

Windows users may want to start using Python 3.6 in the near future.

Python 3.6 was released at the end of the year when the Advent calendar was about to reach its finale.

-Example of news of python3.6 -Those who have confirmed the functions of 3.6 in advance

The Python 3.6 release from a Windows perspective could be summarized as follows:

--String literals have become more convenient, and type descriptions (annotations) have been expanded. -** Even in Windows environment ** The default character code is now UTF-8. ――Windows OS has nothing to do with Python, so it's okay to use it experimentally without thinking about anything.

The default UTF-8 conversion is large. In short, it will be comparable to Linux / Mac, so people in the 2-byte area will be less likely to suffer from extra stress around the character code.

Install on Windows

Download and install the installer from the Official Site.

If you feel a little uneasy because it has just been released, you can install it by uncommenting "Install launcher for all users" for temporary users (..?) py36.PNG

After installation, type python in the console to enter the python3.6 interactive environment:

py36-1.PNG

f "My name is {name}"

The new function of python3.6 "Formatted string literal (PEP-498)" can be used without any problem.

--To learn about new features in python3.6, including formatted string literals You should read the following series of blogs. http://atsuoishimoto.hatenablog.com/entry/2016/12/25/122220

Know Python 3.6 type annotations.

In the following, we will briefly discuss type annotations that enable typed descriptions in Python.

In the dynamic language python, it is not necessary to specify the type in the variable definition.

Example ①:

person.py


class Person :
  def __init__(self):
    self.name = ''
    self.age = 0
  def __init__(self,name ,age):
    self.name = name
    self.age = age
  def greet(self):
    print(f"Hi, I'm  {self.name} .")
    print(f"I am {self.age} years old.")

If you try it in an interactive environment: py361.PNG

The variable age can be of type int or str.

In Python3.6, variable typing can be done widely.

Add a little to example (1) and specify the type for the instance variable of the class.

Example ②:

person.py


class Person :
  #Add type annotation
  name : str
  age : int
  
  def __init__(self):
    self.name = ''
    self.age = 0
  def __init__(self,name ,age):
    self.name = name
    self.age = age
  def greet(self):
    print(f"Hi, I'm  {self.name} .")
    print(f"I am {self.age} years old.")
   

Execution result: py362.PNG

As a result of astonishment, some people may feel uncomfortable that the execution result of Q Taro does not change (although it is possible to describe the type in the argument of the method of Person class, but this Even if the result does not change). The description that specifies the type in Python3.6 is called (static) type annotation and is used for type checking in large-scale development etc. ("Class name.annotations" as shown in the last line of the execution result. (Used like this). It is different from the type specification in compilation languages such as Java and C #.

--For mypy for practical use of Python type annotations, read the following translated document.

http://qiita.com/t2y/items/2a1310608da7b5c4860b

Think about the future of Python type annotations.

Initially, it seems that it will start to be used from the site of team development.

Using Python for calling computational libraries etc. I wouldn't use type annotations for the time being (it doesn't seem to benefit much). On the contrary, in the team that operates many web services etc. with python, type checking using type annotation will be performed.

--Reference: I will use it on CI servers, etc., article http://qiita.com/k-saka/items/8f05c89f675af219e081

It seems that a killer tool can be released.

As I learned from the introduction to Python, in addition to various versions of Cpython (2.x series, 3.y series) that have various implementations in Python, starting with pypy, implementation systems on Jython, Ironpython, DartVM, etc. And so on ... Of course, there are plenty of tools in the library just for historical languages. There are many libraries that are combined with C / C ++ languages. Well-known libraries are good, but there is no guarantee that they will work with your implementation when you want to use a library made by some amazing person. I think that such a thing is to read the source and apply the patch by yourself ... I think that it was the open source culture of python so far, but it seems a bit tough with python which became major due to the recent big data & AI boom. ..

I don't understand mypy very much, so I can't write it as a concrete story, but I think there will soon be a great tool for using Python type annotations to interface with other languages. Or (and expect).

(Bonus) What I want to work on personally.

Recently, I mentioned python several times in Advent Calendar of New Language nim. I was wondering if there are many great tools that combine python and C / C ++, but I think we can also make a tool that combines nim and python that are compiled into C / C ++. if you can, In a form that takes advantage of the features of the compilation language nim, which has a python-like grammar.

The first is a tool that automatically rewrites a model defined in python into nim source code.

Actually, the above code example ② is a rewrite of the structure usage example displayed as "grab" on the top page of nim's official website to python (since python does not have a structure, I wrote it in class .. A simpler python-like description would be possible).

person.nim


type Person = object
  name: string
  age: int

proc greet(p: Person) =
  echo "Hi, I'm ", p.name, "."
  echo "I am ", p.age, " years old."

let p = Person(name:"Jon", age:18)
p.greet() # or greet(p)

Talks like coffeescript-> javascript are commonplace in recent years, and it seems quite likely to automate these conversions themselves, so I'd like to challenge after getting a little more familiar with both languages. And from here onward, the key to ease of use will be the automatic generation of interfaces that include mutual type checking and null safety.

Potential for Windows / Xamarin users

With the recent trend of openness (?), Microsoft seems to be becoming a python-friendly company (python is supported in visual studio). With iOS / Android becoming widespread Is it because of the sense of crisis that the survival of the company will be jeopardized if it becomes the C # one-legged method?

It was xamarin, which was born from the .NET compatible environment mono derived from the Linux culture, that saved Microsoft. The story that C # users can develop on iOS / Android in addition to Windows is very appealing. mono is a CLR environment (C # execution environment) written in C language below. In Xamarin, the code is also written in objective-C / C ++ for iOS / Android support. Xamarin is a "C-language brothers". xamarinがより広く使われ始めると、もっともメジャーなスクリプト言語のひとつpythonを使いたい、C系のライブラリを呼びだしたいとの要求が広まるものと考えられる。ということで、.NET/mono/xamarin界隈では,近いうちにironpythonの話題が登場するのではないかと考える。その時、言語と実行系の組み合わせだけで複雑系になるpython周りの開発現場で型アノテーションを用いた静的解析が大規模に活用されるのではないか(...されるとまずいことになりそうな...)。

--Reference: New reader of IronPython https://www.infoq.com/jp/news/2016/08/IronPython-Leadership ironpython

The end

I changed the punch line of python material to xamarin forcibly as a personal memory.

Xamarin has been open sourced since it was acquired by Microsoft, and in the last six months or so, a lot of information has been released, so it feels like it's finally time to use it. In fact, there are people who want to use such xamarin with python, right? ... So, as soon as I wanted to take a python (and sometimes nim) gaze around xamarin, which might save Microsoft in the future :)

Recommended Posts

Python 3.6 on Windows ... and to Xamarin.
Python on Windows
Integrate Modelica and Python on Windows
[Kivy] How to install Kivy on Windows [Python]
python basic on windows ②
Install python on windows
Install and run Python3.5 + NumPy + SciPy on Windows 10
Put MicroPython on Windows to run ESP32 on Python
(Windows) Causes and workarounds for UnicodeEncodeError on Python 3
Notes on installing Python3 and using pip on Windows7
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Python] How to install OpenCV on Anaconda [Windows]
[Note] Installing Python 3.6 + α on Windows and RHEL
Install ZIP version Python and pip on Windows 10
Put Cabocha 0.68 on Windows and try to analyze the dependency with Python
Run Openpose on Python (Windows)
How to install Python [Windows]
Install watchdog on Windows + Python 3.3
Python on Ruby and angry Ruby on Python
Install Python and Flask (Windows 10)
Python + Kivy development on Windows
Sphinx-autobuild (0.5.2) on Windows7, Python 3.5.1, Sphinx 1.3.5
Fastest Python installation on Windows
Build Python environment on Windows
Update python on Mac to 3.7-> 3.8
Build python environment on windows
I ran python on windows
[Python] [Chainer] [Windows] Install Chainer on Windows
Use Python on Windows (PyCharm)
How to embed mod_wsgi into Apache on Python Windows
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Create a decent shell and python environment on Windows
To avoid seeing hell when installing django-toolbelt on windows, heroku and python3.4 (64bit) ...
Python environment construction memo on Windows 10
Notes on Python and dictionary types
Installing Kivy on Windows10 64bit Python3.5
[Introduction to Python3 Day 1] Programming and Python
Anaconda python environment construction on Windows 10
How to use Dataiku on Windows
Install python2.7 on windows 32bit environment
Introduction to Python Hands On Part 1
Install xgboost (python version) on Windows
Install Python on Windows + pip + virtualenv
Build and install OpenCV on Windows
Install Pytorch on Blender 2.90 python on Windows
How to install pycrypto on Windows
How to deploy django-compressor on Windows
Install pyenv on MacBook Air and switch python to use
Installing Kivy-Designer on Windows10 64bit Python3.5
Install python and Visual Studio Code on windows10 (April 2020 version)
Mecab / Cabocha / KNP on Python + Windows
Mastering pip and wheel on windows
Install Python development environment on Windows 10
Python logging and dump to json
Python CGI file created on Windows
Selenium and python to open google
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
Steps to install python3 on mac
Getting started with Python 3.8 on Windows
Reproduce One-Touch Search on Python 3.7.3. (Windows 10)
How to install music 21 on windows