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

Python

カテゴリー: インポートシステム  閲覧数:320 配信日: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マガジン

週間人気ページランキング / 12-12 → 12-18
順位 ページタイトル抜粋 アクセス数
1 _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?) | エラー 1
1 ゲストコメント一覧ページ 1
2025/12/19 1:02 更新