LoginSignup
0
1

More than 3 years have passed since last update.

python入門[import] 「from relative_module import identifier」 とか

Last updated at Posted at 2019-05-22

目的

import文に関して
 import モジュール
という構文の意識が強くて、
 from AA import BBBB
という構文で、BBBBがモジュールでないのが、どうにも、気持ち悪かった。。。
納得を求めて、調査したが、
結局、以下の記載が一番すっきりしていたので、メモ。

import statement

import statementの説明は、以下。
import moduleは、ほんの一例に過ぎないと読める。
各々のケースの処理内容も説明されているので、更に、納得。

(出典:https://docs.python.org/ja/3/reference/simple_stmts.html#grammar-token-import-stmt)

import_stmt     ::=  "import" module ["as" identifier] ("," module ["as" identifier])*
                     | "from" relative_module "import" identifier ["as" identifier]
                     ("," identifier ["as" identifier])*
                     | "from" relative_module "import" "(" identifier ["as" identifier]
                     ("," identifier ["as" identifier])* [","] ")"
                     | "from" module "import" "*"
module          ::=  (identifier ".")* identifier
relative_module ::=  "."* module | "."+

from.png

まとめ

「docs.python.org/ja/3/reference」が、一番いいときもあると感じた。

関連(本人)

pythonをストレスなく使う!(結局docs.python.orgのreferenceが納得感が高い気が、、、)
英語と日本語、両方使ってPythonを丁寧に学ぶ。

今後

何かあれば、追記します。
コメントなどあれば、お願いします:candy:

0
1
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
0
1