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
190
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.6k
How to Write Robust Python Code
hayaosuzuki
5
3.8k
Unknown Evolution of the Built-in Function pow
hayaosuzuki
0
1.3k
Python for Everyday
hayaosuzuki
1
1.8k
How to Use In-Memory Streams
hayaosuzuki
1
4k
Do you know cmath module?
hayaosuzuki
0
3.1k
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.5k
Other Decks in Technology
See All in Technology
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
180
DynamoDB でスロットリングが発生したとき_大盛りver/when_throttling_occurs_in_dynamodb_long
emiki
1
190
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
150
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
rootlessコンテナのすゝめ - 研究室サーバーでもできる安全なコンテナ管理
kitsuya0828
3
390
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
480
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
610
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
830
Engineer Career Talk
lycorp_recruit_jp
0
170
TypeScript、上達の瞬間
sadnessojisan
46
13k
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
270
Featured
See All Featured
Being A Developer After 40
akosma
86
590k
How to train your dragon (web standard)
notwaldorf
88
5.7k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Making Projects Easy
brettharned
115
5.9k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Producing Creativity
orderedlist
PRO
341
39k
For a Future-Friendly Web
brad_frost
175
9.4k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How GitHub (no longer) Works
holman
310
140k
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