asを使って別名でインポート

Python

カテゴリー: インポートシステム  閲覧数:252 配信日:2018-03-27 10:26


モジュールを別名でインポートするにはasを使用


import モジュール名 as 別名

具体例


▼greeting_module.py
class GreetingClass:
   def sayStr(self, str):
       print str


▼index.py
import greeting_module as g # gという別名でgreeting_moduleをインポート

greeting = g.GreetingClass()
greeting.sayStr("Hello")          # Hello





Pythonでモジュールをインポートする:import, from, as | UX MILK

6. モジュール (module) — Python 3.6.3 ドキュメント
モジュールのインポート方法いろいろ — Python School 2.0.0 documentation
import の使い方 - Life with Python
Pythonで標準ライブラリのモジュールをインポートして使ってみよう
Python/モジュールのインポート - Wikibooks
効率よく開発できる!Pythonでimportを使う方法 | TechAcademyマガジン