Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
importを理解したかった
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
tera
February 20, 2017
670
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
importを理解したかった
平成29年2月18日(土): 第四回 帰ってきたhojiroLT にて話しました未完のスライドです
tera
February 20, 2017
More Decks by tera
See All by tera
ピッてやるとシュッてなるやつを作った話
tera
0
270
Pythonを読む
tera
0
230
RustでShell作ろう
tera
0
970
HTTPをしゃべろう~Firefoxになるために~
tera
0
270
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
480
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
600
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
630
Writing Fast Ruby
sferik
630
63k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
From π to Pie charts
rasagy
1
400
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Building AI with AI
inesmontani
PRO
1
1.3k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
630
Transcript
importを 理解できなかった話 @tera_3939
自己紹介 • Twitter:@tera_3939 • 手書きレポート・正弦波学科 • 許さねえぞ
アジェンダ • 謝罪 • importについて • __import__()が行う処理 • hook
アジェンダ • 謝罪 • importについて • __import__()が行う処理 • hook
スライドができませんでした
理由:怠惰
importとは • あるモジュールのコードから他のモジュールのコードをイン ポートすること • import math • from math
import pi • 他の言語だとuseとかusingとか
importの方法 • import文を使う • importlib.import_module()を使う • __import__()を使う(非推奨)
importの方法 • import文を使う ← これにちょっかいする • importlib.import_module()を使う • __import__()を使う(非推奨)
import文の処理 • 指定されたモジュール名を検索する • 適切な引数で__import__()を呼び出す • 見つかったら指定された名前にそのモジュールを束縛する • import math
-> mathという名前にmathを束縛 • import math as m -> mという名前にmathを束縛
import文の処理 • 指定されたモジュール名を検索する • 適切な引数で__import__()を呼び出す • 見つかったら指定された名前にそのモジュールを束縛する • import math
-> mathという名前にmathを束縛 • import math as m -> mという名前にmathを束縛
__import__()の処理 • sys.modulesを検索する • すでに読み込まれているモジュールのキャッシュ • 見つからなければimport機構が起動する • 有る場合はそのモジュールのmodule specを返す
• module specはモジュールのロードに使われるオブジェクト • 無い場合はImportErrorになる
import機構 • ファインダー, ローダーと呼ばれるオブジェクトが使用される • ファインダー • モジュールが見つかった場合module specを返す •
ローダー • モジュールをロードする • module specのloader属性に詰め込まれる
importをhookする • sys.meta_pathに自作ファインダーを加える • sys.path_hooksに自作ファインダーを加える • sys.path内のパスを処理する際に使用される
sys.meta_path • メタパス・ファインダー・オブジェクトのリスト • このオブジェクトが持つメソッドfind_spec()を順に呼び出す • モジュールが見つかればmodule specを返す • 見つからなければNoneを返す
おしまい • ごめんなさい…… • そのうちブログにまとめます……