LoginSignup
6
5

More than 5 years have passed since last update.

もうすぐリリースされるPython3.7環境をDockerで作る

Posted at

Python3.7がもうすぐリリースされるようです。

Release Schedule

リリース前に新機能を試してみたいと思います。

こういうときはソースからビルドするのが一昔前のやり方でしたが、今時はDockerで簡単に試すことができます。
Docker Hub では Pythonのイメージが公開されていて、先日公開されたばかりの3.7.0b4のタグもあります。

DockerでPython3.7のインタプリタを実行
$ docker run -it --rm python:3.7.0b4
Unable to find image 'python:3.7.0b4' locally
3.7.0b4: Pulling from library/python
cc1a78bfd46b: Pull complete
:
:
Python 3.7.0b4 (default, May  5 2018, 02:57:38)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

デフォルトのインタプリタだと使いにくいのでIPythonをインストールしたイメージを作成しておくと便利です。

Dockerfile
FROM python:3.7.0b4

RUN pip install ipython

CMD ipython
イメージの作成
$ docker build . -t tag1216/ipython:3.7.0b4
実行
$ docker run -it --rm tag1216/ipython:3.7.0b4
Python 3.7.0b4 (default, May  5 2018, 02:57:38)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]:

PEP 557: Data Classes を試してみます。

In [1]: from dataclasses import dataclass

In [2]: @dataclass
   ...: class MyClass:
   ...:     a: int
   ...:     b: str
   ...:

In [3]: obj = MyClass(1, 'a')

In [4]: obj
Out[4]: MyClass(a=1, b='a')

In [5]: obj.a = 999

In [6]: obj
Out[6]: MyClass(a=999, b='a')
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5