Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Tasting "Python Distilled"
Search
HayaoSuzuki
November 30, 2023
Technology
0
240
Tasting "Python Distilled"
BPStudy#195
https://bpstudy.connpass.com/event/301504/
HayaoSuzuki
November 30, 2023
Tweet
Share
More Decks by HayaoSuzuki
See All by HayaoSuzuki
Let's implement useless Python objects
hayaosuzuki
0
1.7k
How to Write Robust Python Code
hayaosuzuki
5
4k
Unknown Evolution of the Built-in Function pow
hayaosuzuki
0
1.4k
Python for Everyday
hayaosuzuki
1
1.9k
How to Use In-Memory Streams
hayaosuzuki
1
4.3k
Do you know cmath module?
hayaosuzuki
0
3.2k
Elementary Number Theory with Python
hayaosuzuki
1
3.4k
Django QuerySet "ARE" Patterns
hayaosuzuki
0
3.2k
A Modernization of Legacy Django Based Applications
hayaosuzuki
1
7.6k
Other Decks in Technology
See All in Technology
re:Invent 2024のふりかえり
beli68
0
100
カップ麺の待ち時間(3分)でわかるPartyRockアップデート
ryutakondo
0
130
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
190
0→1事業こそPMは営業すべし / pmconf #落選お披露目 / PM should do sales in zero to one
roki_n_
PRO
1
920
🌏丸い地球を効率的に平たくする 〜🗺️地図の幾何学とWeb地図技術〜
syotasasaki593876
0
140
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
6
54k
ABWGのRe:Cap!
hm5ug
1
110
Copilotの力を実感!3ヶ月間の生成AI研修の試行錯誤&成功事例をご紹介。果たして得たものとは・・?
ktc_shiori
0
330
Reactフレームワークプロダクトを モバイルアプリにして、もっと便利に。 ユーザに価値を届けよう。/React Framework with Capacitor
rdlabo
0
110
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
140
完全自律型AIエージェントとAgentic Workflow〜ワークフロー構築という現実解
pharma_x_tech
0
320
AWSの生成AIサービス Amazon Bedrock入門!(2025年1月版)
minorun365
PRO
7
460
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Scaling GitHub
holman
459
140k
Six Lessons from altMBA
skipperchong
27
3.6k
Building an army of robots
kneath
302
45k
A designer walks into a library…
pauljervisheath
205
24k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Optimising Largest Contentful Paint
csswizardry
33
3k
A Philosophy of Restraint
colly
203
16k
Designing for Performance
lara
604
68k
Writing Fast Ruby
sferik
628
61k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Transcript
Python Distilled ࢼҿձ Hayao Suzuki BPStudy #195 November 30, 2023
ࣗݾհ ͓લ୭Α Name Hayao Suzukiʢླɹॣʣ ///////// Twitter X @CardinalXaro Work
Software Developer @ BeProud Inc. › גࣜձࣾϏʔϓϥυ › IT ษڧձࢧԉϓϥοτϑΥʔϜ › Python ಠֶϓϥοτϑΥʔϜ › γεςϜ։ൃυΩϡϝϯταʔϏε 2 / 60
ࣗݾհ ൃදͨ͠τʔΫʢൈਮʣ › SymPy ʹΑΔࣜॲཧ (PyCon JP 2018) › ΠϯϝϞϦʔετϦʔϜ׆༻ज़
(PyCon JP 2020) › ΈࠐΈؔ pow ͷΒΕ͟ΔਐԽ (PyCon JP 2021) › Let’s implement useless Python objects(PyCon APAC 2023) https://xaro.hatenablog.jp/ ʹҰཡ͕͋Γ·͢ɻ 3 / 60
ࣗݾհ ༁ͨ͠ຊ › Python Distilled(O’Reilly Japan) ຊͷओ ༁ͨ͠ຊ › ೖ
Python 3 ୈ 2 ൛ (O’Reilly Japan) › ϩόετ Python(O’Reilly Japan) 4 / 60
ࠓͷςʔϚ 5 / 60
ࠓͷςʔϚ 6 / 60
Python Distilled ݪஶɿPython Distilled ஶऀ David M. Beazley ग़൛ 2021
9 ݄ ग़൛ࣾ Addison-Wesley(Pearson) ༁ɿPython Distilled ϓϩάϥϛϯάݴޠ Python ͷΤοηϯε ༁ऀ ླ ॣ ग़൛ 2023 10 ݄ ग़൛ࣾ ΦϥΠϦʔɾδϟύϯ Pearson ͱͷܖ্ɺ༁ͷදࢴಈͰͳ͍ɻ 7 / 60
༁ͷྲྀΕ ༁ग़൛·Ͱͷي › 2022 4 ݄ ڵຯຊҐͰݪஶిࢠ൛Λߪೖ › 2022
5 ݄ ΦϥΠϦʔͷฤूऀʹݪஶΛհ͢ΔʢࡶஊϨϕϧʣ › 2022 6 ݄ ༁൛ݖऔಘʹ͚ͯಈ͖ग़͢ › 2022 7 ݄ ༁൛ݖऔಘɺ༁ͷଧɺ༁ʹઓ͠Α͏ͱܾҙ › 2022 9 ݄ ༁Λ։࢝͢Δʢϩόετ Python ͷ༁ͱฒߦʣ › 2023 4 ݄ Ұ௨Γ༁͕ྃɺਪᏏͷʑ › 2023 9 ݄ ༁࡞ۀྃ 8 / 60
Python Distilled ͬͯͲΜͳຊʁ ݪஶऀʮ͡ΊʹʯΑΓ ͜ͷʰPython Distilledʱ Python ʹΑΔϓϩάϥϛϯάʹ͍ͭͯͷॻ੶Ͱ͢ɻ Python ͰՄೳͳ͜ͱɺ͋Δ͍ߦΘΕͨ͜ͱΛͯ͢จॻԽ͠Α͏ͱ͍͏Θ͚Ͱ
͋Γ·ͤΜɻຊॻͷతɺݱతͰ͋Γݫબɺͭ·Γৠཹʢdistilledʣ͞Εͨϓ ϩάϥϛϯάݴޠ Python ͷ֩৺Λհ͢Δ͜ͱͰ͢ɻ ʢதུʣ͔͠͠ɺͦΕ·ͨɺ ιϑτΣΞϥΠϒϥϦΛॻ͖ɺPython ͷԿͨΔ͔ΛΓɺԿ͕࠷ʹཱ͔ͭΛ ݟग़ͨ݁͠ՌͰ͋ΔͷͰ͢ɻ 9 / 60
ͭ·ΓɺͲΜͳຊʁ ҰݴͰ·ͱΊΔͱ ϓϩάϥϛϯάݴޠ Python ͦͷͷʹಛԽͨ͠ຊ 10 / 60
ॻධ ///////// Twitter X Ͱݟ͔͚ͨॻධ No human should be allowed
to write Python code before reading it. ौ͞ΜʹΑΔॻධ ண࣮ʹ Python ΛࣗΒͷ݂ʹ͍͖͍ͯͨ͠ਓ͚ͷຊͰ͢ɻ 11 / 60
Python ͷֶͼํ ܅ͨͪͲ͏ Python ΛֶͿ͔ 12 / 60
Python ͷֶͼํ https://docs.python.org/ja/3/ 13 / 60
Python ͷֶͼํ Python ެࣜυΩϡϝϯτ͕ॆ࣮ › https://docs.python.org/ja/3/ ΞϨͲ͜ʹॻ͍ͯ͋Δͷʁ ͦ͏ͦ͏ɺΞϨͩΑɺΞϨɺ͋ͦ͜ʹ͋ΔΑɻ ൃදऀͷӨڹͰதϑΝϯͰ͕ͨ͠ɺ࠷ۙ·ͬͨ͘ٿΛݟ͍ͯ·ͤΜɻ 14
/ 60
ಥવͷΫΠζ Python ͷΞϨɺͲ͜ʹॻ͍ͯ͋Δ͔ͳ ΫΠζʂ 15 / 60
ୈ 1 ɿγϯάϧτϯͷൺֱ None TrueɺFalse γϯάϧτϯͰ͋Γɺγϯάϧτϯ is จͰൺֱ͠·͢ɻ
͜ͷҙࣄ߲υΩϡϝϯτͷͲ͜ʹॻ͔Ε͍ͯΔͰ͠ΐ͏͔ʁ 16 / 60
ୈ 1 ɿγϯάϧτϯͷൺֱ None TrueɺFalse γϯάϧτϯͰ͋Γɺγϯάϧτϯ is จͰൺֱ͠·͢ɻ
͜ͷҙࣄ߲υΩϡϝϯτͷͲ͜ʹॻ͔Ε͍ͯΔͰ͠ΐ͏͔ʁ ղɿ2 Օॴ › ݴޠϦϑΝϨϯεʢҙשىʣ › PEP 8ʢ؆୯ͳཧ༝ʣ ࣮࣭తʹ PEP 8 ͚ͩͱݴ͑Δɻ 17 / 60
ୈ 2 ɿؔͷσϑΥϧτҾ ؔͷσϑΥϧτҾΛ͏ࡍΠϛϡʔλϒϧͳΦϒδΣΫτΛ͍·͢ɻ͜ͷ ҙࣄ߲υΩϡϝϯτͷͲ͜ʹॻ͔Ε͍ͯΔͰ͠ΐ͏͔ʁ 18 / 60
ୈ 2 ɿؔͷσϑΥϧτҾ ؔͷσϑΥϧτҾΛ͏ࡍΠϛϡʔλϒϧͳΦϒδΣΫτΛ͍·͢ɻ͜ͷ ҙࣄ߲υΩϡϝϯτͷͲ͜ʹॻ͔Ε͍ͯΔͰ͠ΐ͏͔ʁ ղɿ2 Օॴ › νϡʔτϦΞϧʢҙשىʣ
› ϓϩάϥϛϯά FAQʢσϑΥϧτҾͷΈʹ͍ͭͯʣ 19 / 60
ୈ 3 ɿwith จ Python 2.5 ͔Β with จ͕ಋೖ͞Ε·ͨ͠ɻwith
จͷ͍ํͲ͜ʹॻ͔Ε͍ͯ ΔͰ͠ΐ͏͔ʁ 20 / 60
ୈ 3 ɿwith จ Python 2.5 ͔Β with จ͕ಋೖ͞Ε·ͨ͠ɻwith
จͷ͍ํͲ͜ʹॻ͔Ε͍ͯ ΔͰ͠ΐ͏͔ʁ ղɿ3 Օॴ › νϡʔτϦΞϧʢଘࡏΛࣔࠦ͢Δ͚ͩʣ › ݴޠϦϑΝϨϯεʢwith จͷߏจͱίϯςΩετϚωʔδϟʹ͍ͭͯʣ › PEP 343ʢwith ͷಋೖܦҢഎܠʹ͍ͭͯʣ 21 / 60
ୈ 4 ɿ__init__() ͱ__new__() ΫϥεͷΠϯελϯεΛ࣮ࡍʹੜ͢Δͷ__new__()ɺΠϯελϯεͷॳظԽ __init__() Ͱ͢ɻ͜ͷؔʹ͍ͭͯॻ͔Ε͍ͯΔͷͲ͜Ͱ͠ΐ͏͔ʁ 22 /
60
ୈ 4 ɿ__init__() ͱ__new__() ΫϥεͷΠϯελϯεΛ࣮ࡍʹੜ͢Δͷ__new__()ɺΠϯελϯεͷॳظԽ __init__() Ͱ͢ɻ͜ͷؔʹ͍ͭͯॻ͔Ε͍ͯΔͷͲ͜Ͱ͠ΐ͏͔ʁ ղɿ1 Օॴ
› ݴޠϦϑΝϨϯε __init__() ίϯετϥΫλ͡Όͳ͍Αʂ 23 / 60
ୈ 5 ɿfrom module import * from module import
*͕ՄೳͳͷϞδϡʔϧϨϕϧͷΠϯϙʔτͰɺΫϥεؔ ෦ͰͰ͖·ͤΜɻ͜ͷࣄ࣮ʹ͍ͭͯॻ͔Ε͍ͯΔͷͲ͜Ͱ͠ΐ͏͔ʁ 24 / 60
ୈ 5 ɿfrom module import * from module import
*͕ՄೳͳͷϞδϡʔϧϨϕϧͷΠϯϙʔτͰɺΫϥεؔ ෦ͰͰ͖·ͤΜɻ͜ͷࣄ࣮ʹ͍ͭͯॻ͔Ε͍ͯΔͷͲ͜Ͱ͠ΐ͏͔ʁ ղɿ1 Օॴ › ݴޠϦϑΝϨϯε ͨͩ͠ɺfrom module import *͏ͳͱҙשى͞Ε͍ͯΔ 25 / 60
Python ͷֶͼํ Python ެࣜυΩϡϝϯτ͕ॆ࣮ › େମެࣜυΩϡϝϯτ PEP ʹॻ͔Ε͍ͯΔ › νϡʔτϦΞϧͱඪ४ϥΠϒϥϦ͚ͩͰԿͱ͔ͳΔ
ެࣜυΩϡϝϯτେ͗͢Δ › ಥͬࠐΜͩ༰ͩͱݴޠϦϑΝϨϯε PEP Λ୳Δ͜ͱʹͳΔ › ݴޠϦϑΝϨϯεʮ͚ͦͬͳ͍ॻ͖ํʯ ɺಡΈతʹಡΊͳ͍ɻ 26 / 60
Python ͷֶͼํ ॻ੶͔ΒֶͿɿೖॻ › جຊతʹॳ৺ऀ͖ɺಥͬࠐΜͩ༰ʹ৮Ε͍ͯͳ͍ › චऀͷͱͯ͠औࣺબ͕ߦΘΕ͍ͯΔ ೖॻͷ۩ମྫ › ʰೖ
Python 3 ୈ 2 ൛ʱ ʢ800 ϖʔδʣ ɺೖ෦ 270 ϖʔδ › ʰPython νϡʔτϦΞϧ ୈ 4 ൛ʱ ʢ264 ϖʔδʣ ɺఈຊެࣜυΩϡϝϯτ 27 / 60
Python ͷֶͼํ ॻ੶͔ΒֶͿɿ ʢൺֱతʣߴ͍Ϩϕϧͷຊ › Python ݴޠΛཏ͠Α͏ͱ͍ͯ͠Δ › ඞવతʹް͘ͳΓɺಡΈ௨͢ͷ͕େม ߴ͍Ϩϕϧͷ۩ମྫ
› ʰॳΊͯͷ Python ୈ 3 ൛ʱ ʢ808 ϖʔδʣ ɺݪॻୈ 5 ൛ 1648 ϖʔδ › ʰFluent Pythonʱ ʢ832 ϖʔδʣ ɺݪॻୈ 2 ൛ 983 ϖʔδ 28 / 60
Python ͷֶͼํ Πϯλʔωοτɺ·ͨݕࡧͰ୳͢ › ۄੴࠞ߹ › ݁ہެࣜυΩϡϝϯτʹམͪண͘ › ௐ͍ͨ͜ͱ͕Θ͔͍ͬͯͳ͍ͱ͑ͳ͍ ࣭͕ߴ͍
Web ࢿྉ › ʰPython Boot Camp Textʱॳ৺ऀ͚νϡʔτϦΞϧΠϕϯτͷࢿྉ › ʰPython TutorʱPython ͷಈ͖Λࢹ֮తʹ֬ೝͰ͖ΔαΠτ 29 / 60
Python ͷֶͼํ ࠷ۙͷྲྀߦΓɿGPTs ʹฉ͍ͯΈΔ › Զͨͪͷ ChatGPT ઌੜ › ௐ͍ͨ͜ͱ͕Θ͔͍ͬͯͳ͍ͱ͑ͳ͍
› ͖ͨͨͱͯ͠࠷ద › ͋Δఔ Python ΛΘ͔͍ͬͯͳ͍ͱ͍͜ͳͤͳ͍ʢࢲݟʣ ΤϨϛϠ 14:14ʢॻڠձڞಉ༁ΑΓʣ ओࢲʹݴΘΕͨɻ ʮ༬ݴऀͨͪɺࢲͷ໊ʹΑِͬͯΓͷ༬ݴΛ͍ͯ͠Δɻࢲ൴Β ΛݣΘͨ͜͠ͱͳ͘ɺ൴Βʹ໋ͨ͜͡ͱͳ͘ɺ൴Βʹޠͬͨ͜ͱͳ͍ɻ൴Βِ Γͷݬͱۭ͍͍͠ͱࣗͷ৺ͷ͖ٗΛ͋ͳ͕ͨͨʹ༬ݴ͍ͯ͠Δͷͩɻ 30 / 60
Python ͷֶͼํ Python Distilled › Python ݴޠͦͷͷʹಛԽͨ͠ຊ › ݴޠϦϑΝϨϯεʹॻ͍ͯ͋Δ͜ͱ͕ 336
ϖʔδʹ·ͱ·͍ͬͯΔ Python Distilled ʹॻ͍͍ͯͳ͍͜ͱ › ܕώϯτपΓʢ ʰϩόετ Pythonʱಡ͏ʣ › ඇಉظॲཧ › 3rd ύʔςΟϥΠϒϥϦɺΤίγεςϜपΓ 31 / 60
FAQ ຊʹΑ͋͘Δ࣭ ʰPython Distilledʱͱʰೖ Python 3 ୈ 2 ൛ʱͷҧ͍ʁ Python
Distilled ʹॻ͍͍ͯͳ͍͜ͱ › ʰೖ Python 3 ୈ 2 ൛ʱΤίγεςϜ͔ͬ͠Γ৮Ε͍ͯΔ › ʰPython DistilledʱݴޠίΞʹಛԽͨ͠ຊ 32 / 60
Python Distilled ݁ہɺԿ͕ॻ͍ͯ͋Δͷʁ 33 / 60
1 ষ Python ͷجૅ 1 ষ Python ͷجૅ › มσʔλܕɺࣜɺ੍ޚߏɺؔɺΫϥεɺೖग़ྗʹ͍ͭͯͷ֓આ
› ݪॻ Python 3.8 Ҏ߱Λఆɺ༁Ͱ 3.11 ·ͰରԠͰ͖ΔΑ͏ʹͨ͠ › Θ͔Δਓඈͯ͠େৎ 34 / 60
1 ষ Python ͷجૅ ྫɿελοΫϕʔεͷܭࢉػ େͷ߹ɺܧঝ࠷ྑͷղܾࡦͰ͋Γ·ͤΜɻྫ͑ɺ୯७ͳελοΫϕʔεͷܭ ࢉػΛ࡞Γ͍ͨͱ͠·͢ɻ ༁࣌ʹ๊͍ͨݒ೦ › ʮελοΫϕʔεͷܭࢉػʯઆ໌ͳ͠Ͱ௨͡Δͷ͔
› ٯϙʔϥϯυه๏ͷઆ໌ΛՃ͢Δ͖͔ 35 / 60
2 ষ ԋࢉࢠɺࣜɺσʔλૢ࡞ 2 ষ ԋࢉࢠɺࣜɺσʔλૢ࡞ › ࣜɺԋࢉࢠɺධՁنଇʹ͍ͭͯ › جຊతͳσʔλߏʹ͍ͭͯઆ໌
36 / 60
2 ষ ԋࢉࢠɺࣜɺσʔλૢ࡞ ҉తͳਅِධՁͷ᠘ def f(x, items=None): if not items:
items = [] items.append(x) return items 37 / 60
2 ষ ԋࢉࢠɺࣜɺσʔλૢ࡞ ࣮ߦྫ >>> f(4) [4] >>> a =
[] >>> f(3, a) [3] >>> a # ߋ৽͞Εͳ͍ʂ [] 38 / 60
3 ষ ϓϩάϥϜͷߏͱ੍ޚߏ 3 ষ ϓϩάϥϜͷߏͱ੍ޚߏ › ݅ذɺϧʔϓɺྫ֎ɺίϯςΩετϚωʔδϟʹ͍ͭͯ › ʮ3.4
ྫ֎ʯྫ֎ͳ͘ಡ͏ʂ 39 / 60
3 ষ ϓϩάϥϜͷߏͱ੍ޚߏ ྫɿྫ֎Λอ࣋͢Δมͷੜଘൣғ try: int("N/A") except ValueError as e:
print("Failed:", e) print(e) # NameError 40 / 60
3 ষ ϓϩάϥϜͷߏͱ੍ޚߏ ྫɿྫ֎ͷ࿈ try: x = int("N/A") except Exception
as e: raise ApplicationError("It failed") from e ྫɿఆ֎ͷ࿈ try: x = int("N/A") except Exception as e: print("It failed:", err) # NameError 41 / 60
3 ষ ϓϩάϥϜͷߏͱ੍ޚߏ __cause__ଐੑͱ__context__ଐੑ › __cause__ଐੑҙਤͯ͠ྫ֎Λ࿈ͨ࣌͠ʹࢀর͢Δ › __context__ଐੑྫ֎ॲཧதͷఆ֎ͷྫ֎ൃੜ࣌ͷใݯ 42 /
60
4 ষ ΦϒδΣΫτɺܕɺϓϩτίϧ 4 ষ ΦϒδΣΫτɺܕɺϓϩτίϧ › Python ͷجຊతͳΦϒδΣΫτϞσϧͱϝΧχζϜʹ͍ͭͯ ›
PyCon APAC 2023 ͷൃදͷݩωλͷ 1 ͭ 43 / 60
4 ষ ΦϒδΣΫτɺܕɺϓϩτίϧ ྫɿࢀরΧϯτ >>> a = 37 #
37 Λ࣋ͭΦϒδΣΫτΛ࡞͢Δ >>> b = a # ΦϒδΣΫτͷࢀরΧϯτ૿Ճ >>> c = [] >>> c.append(b) # ΦϒδΣΫτͷࢀরΧϯτ૿Ճ 44 / 60
4 ষ ΦϒδΣΫτɺܕɺϓϩτίϧ ྫɿࢀরͱίϐʔ >>> a = [1, 2, 3,
4] >>> b = a # b a ͷࢀর >>> b is a True >>> b[2] = -100 # b ͷཁૉΛมߋ͢Δ >>> a # a ͷཁૉมߋ͞ΕΔ [1, 2, -100, 4] 45 / 60
4 ষ ΦϒδΣΫτɺܕɺϓϩτίϧ ྫɿܕͱුಈখܕ >>> a = 42 >>> b
= 3.7 >>> a.__add__(b) NotImplemented >>> b.__radd__(a) 45.7 46 / 60
5 ষ ؔ 5 ষ ؔ › ؔఆٛɺద༻ɺείʔϓɺΫϩʔδϟɺσίϨʔλɺؔܕϓϩάϥϛϯά › 5.16
અͱ 5.17 અͷίʔϧόοΫؔʹؔ͢Δઆ໌༰͕ೱ͍ 47 / 60
5 ষ ؔ ྫɿಈతͳؔੜ def make_init(*names): params = ", ".join(names)
code = f"def __init__(self, {params}):\n" for name in names: code += f" self.{name} = {name}\n" d = {} exec(code, d) return d["__init__"] NamedTuple @dataclass Ͱ׆༻͞Ε͍ͯΔςΫχοΫ 48 / 60
6 ষ δΣωϨʔλ 6 ষ δΣωϨʔλ › δΣωϨʔλͷجૅ͔ΒԠ༻·Ͱ › ʮίϧʔνϯʯͷྺ࢙
49 / 60
6 ষ δΣωϨʔλ ྫɿδΣωϨʔλͷҕৡ def flatten(items): for i in items:
if isinstance(i, list): yield from flatten(i) else: yield i a = [1, 2, [3, [4, 5], 6, 7], 8] for x in flatten(a): print(x, end=" ") 50 / 60
6 ষ δΣωϨʔλ ྫɿ֦ுδΣωϨʔλ def receiver(): print("Ready to receive") while
True: n = yield print("Got", n) >>> r = receiver() >>> r.send(None) Ready to receive >>> r.send("Hello") Got Hello >>> r.close() 51 / 60
7 ষ Ϋϥε 7 ষ Ϋϥε › Ϋϥεʹؔ͢Δ֓೦ΛτοϓμϯͰֶͿ › ౸ୡ૬ϚχΞοΫ͕ͩɺ͍ͬͯΔͱʹཱͭ͜ͱ͋Δ͔͠Εͳ͍
52 / 60
7 ষ Ϋϥε ϝιουղܾॱংͷϧʔϧ 1 ੜΫϥεৗʹجఈΫϥεΑΓઌʹνΣοΫ͞ΕΔ 2 جఈΫϥε͕ෳ͋Δ߹ɺܧঝͨ͠ॱʹνΣοΫ͞ΕΔ ྫɿC ̏ઢܕԽΞϧΰϦζϜͰܾఆͰ͖ͳ͍ྫ
class X: pass class Y(X): pass class Z(X, Y): pass # TypeError 53 / 60
8 ষ Ϟδϡʔϧͱύοέʔδ 8 ষ Ϟδϡʔϧͱύοέʔδ › Ϟδϡʔϧͷ֓೦͕য › ύοέʔδϯάʹ͍ͭͯ৮Ε͍ͯͳ͍
54 / 60
8 ষ Ϟδϡʔϧͱύοέʔδ import module ͱ from module import func
ͷҧ͍ › import module ৽ͨʹ໊લۭؒΛੜ͢Δ › from module import func ࣮ߦ͞Ε໊ͨલۭؒʹ func ΛՃ͢Δ from module import func ͷํ͕͍ʁ › ؾͷ͍ͤͰ͢ › Python ͕ཪଆͰ import module Λ͢ΔͷͰɺؔ͋Γ·ͤΜ 55 / 60
9 ষ ೖྗͱग़ྗ 9 ষ ೖྗͱग़ྗ › I/O ॲཧʹඞཁͳςΫχοΫͱநԽ ›
ޙͷ I/O ϥΠϒϥϦͷ֓ཁྲྀ͠ಡΈͰ OK 56 / 60
9 ষ ೖྗͱग़ྗ ྫɿopen() ؔͷཪଆ import io raw = io.FileIO("filename.txt",
"r") # ੜόΠφϦϞʔυ buffered = io.BufferedReader(raw) # όοϑΝ͖όΠφϦಡΈࠐΈ file = io.TextIOWrapper(buffered, encoding="utf-8") # ςΩετϞʔυ 57 / 60
10 ষ ΈࠐΈؔͱඪ४ϥΠϒϥϦ 10 ষ ΈࠐΈؔͱඪ४ϥΠϒϥϦ › ΈࠐΈؔͱඪ४ϥΠϒϥϦɺΈࠐΈྫ֎ͷҰཡ › ྲྀ͠ಡΈͰ
OK 58 / 60
·ͱΊ ·ͱΊ › ݴޠϦϑΝϨϯεΛಡΊେମॻ͍ͯ͋Δ › ͔͠͠ɺݴޠϦϑΝϨϯεΛಡΈ௨͢ͷ͍͠ › ʰPython DistilledʱͰຊʹඞཁͳͱ͜Ζ͚ͩखʹೖΕΑ͏ 59
/ 60
·ͱΊ ͬͦ͘͞ߪೖ͠Α͏ › https://www.oreilly.co.jp/books/9784814400461/ › https://www.ohmsha.co.jp/book/9784814400461/ ΦϥΠϦʔֶशϓϥοτϑΥʔϜͱ › https://www.oreilly.co.jp/online-learning/ ›
6 ສҎ্ͷॻ੶ͱ 3 ສ࣌ؒҎ্ͷಈըʢຊޠ͋Δʂʣ › ۀքΤΩεύʔτʹΑΔϥΠϒΠϕϯτ › ΠϯλϥΫςΟϒͳγφϦΦͱαϯυϘοΫεΛ࣮ͬͨફతͳֶश › ެࣜೝఆࢼݧରࡦࢿྉ › ʰPython DistilledʱΦϥΠϦʔֶशϓϥοτϑΥʔϜͰಡΈ์ʢ͍͢͝ʣ 60 / 60