$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python Object
Search
Stephen Finucane
July 12, 2016
Technology
0
34
Python Object
How objects work in Python. A talk I gave to OSIC members, October 2015.
Stephen Finucane
July 12, 2016
Tweet
Share
More Decks by Stephen Finucane
See All by Stephen Finucane
Steps Down the OpenAPI Path
stephenfin
0
17
Manage your OpenStack resources from Kubernetes with ORC
stephenfin
0
28
API Contracts: Bringing OpenAPI and typing to OpenStack
stephenfin
0
190
Zero-downtime upgrades with SQLAlchemy + Alembic
stephenfin
0
820
OpenStack from 10,000ft
stephenfin
0
720
Teaching padawans to chop wood and carry water in their open source journey
stephenfin
0
280
What is Nova?
stephenfin
0
490
A Documentation-Driven Approach to Building APIs
stephenfin
0
230
A Lion, a Head, and a Dash of YAML (PyCon Limerick 2020)
stephenfin
0
380
Other Decks in Technology
See All in Technology
AIエージェント開発と活用を加速するワークフロー自動生成への挑戦
shibuiwilliam
4
560
AWSを使う上で最低限知っておきたいセキュリティ研修を社内で実施した話 ~みんなでやるセキュリティ~
maimyyym
2
1.8k
AWS Security Agentの紹介/introducing-aws-security-agent
tomoki10
0
340
2025年 開発生産「可能」性向上報告 サイロ解消からチームが能動性を獲得するまで/ 20251216 Naoki Takahashi
shift_evolve
PRO
2
210
MLflowダイエット大作戦
lycorptech_jp
PRO
1
150
通勤手当申請チェックエージェント開発のリアル
whisaiyo
3
250
mairuでつくるクレデンシャルレス開発環境 / Credential-less development environment using Mailru
mirakui
5
570
AIの長期記憶と短期記憶の違いについてAgentCoreを例に深掘ってみた
yakumo
4
460
Amazon Bedrock Knowledge Bases × メタデータ活用で実現する検証可能な RAG 設計
tomoaki25
6
1.4k
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
130
プロンプトやエージェントを自動的に作る方法
shibuiwilliam
15
15k
AWS re:Invent 2025~初参加の成果と学び~
kubomasataka
0
150
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
330
39k
The Invisible Side of Design
smashingmag
302
51k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
61k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
47k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
Music & Morning Musume
bryan
46
7k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
180
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Designing Powerful Visuals for Engaging Learning
tmiket
0
180
Designing for Performance
lara
610
69k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
200
Being A Developer After 40
akosma
91
590k
Transcript
Stephen Finucane Software Developer, OpenStack Team Intel Shannon
What is Object Orientated design, and why do we care?
What is an object?
Know Java, and know Python is not Java These slides
compare the two, assuming Java knowledge for fair comparison. Don’t try to write Python like Java, though.
None
class MyClass(object): def __init__(self, *args, **kwargs): pass def do_stuff(self): print('doing
stuff') >> instance = MyClass() >> instance.do_stuff() doing stuff classes.py: An example of classes in Python
class MyClass(object): def __init__(self, *args, **kwargs): pass def do_stuff(self): print('doing
stuff')
object is Python being explicit You don’t need it in
Python 2, but you should use it to get “new style classes”
self is also Python being explicit Think of it like
the ‘this’ keyword in Java
public class MyClass { String name; ... public void setName(String
name) { this.name = name; } } MyClass.java: The ‘this’ keyword
class MyClass(object): name = None ... def set_name(self, name): self.name
= name self._example.py: The ‘self’ keyword
None
public class MyClass { public MyClass(String name) { ... }
public MyClass(String name, int age) { ... } } MyClass.java: Constructors in Java
class MyClass(object): def __init__(name, age=None): ... constructors.py: Constructors in Python
public class MyClass { public void display() { System.out.println("Hello, world!");
} } public class MySubClass extends MyClass { public void display() { System.out.println("Testing 123"); } } MyClass.java, MySubClass.java: Inheritance in Java
class MyClass(object) { def display(self): print('Hello world') class MySubClass(MyClass): def
display(self): print('Testing 123') constructors.py: Constructors in Python
public class MySubClass extends MyClass { public void display() {
super.display(); System.out.println("Testing 123"); } } MyClass.java, MySubClass.java: Inheritance in Java
class MySubClass(MyClass): def display(self): super(MySubClass, self).display(self) print('Testing 123') superclasses.py: Accessing
the Super Class
None
public interface Animal { public void eat(); public void travel();
} public class Mammal implements Animal { public void eat() { System.out.println("Mammal eats"); ... Animal.java, Mammal.java: Interfaces in Java
class Mammal: def eat(self): print('Mammal eats') ... class Reptile: def
eat(self): print('Reptile eats') ... animals.py: Duck Typing in Python
None
>> stephens_boat = Boat(...) >> ankurs_boat = Boat(...) >> stephens_boat
> ankurs_boat True The data model in practice
class Boat(object): """Model a boat.""" length = 0 color =
None def __init__(self, length, color): ... def __gt__(self, other): return self.length > other.length: boat.py: Using the data model
__lt__ - less than __le__ - less than or equal
__eq__ - equal __ne__ - not equal __gt__ - greater than __ge__ - greater than or equal __cmp__ - fallback, if above not implemented boat.py: Using the data model
>>> stephens_boat = Boat(100, 'red') >>> stephens_boat.__doc__ Model a boat.
>>> stephens_boat.__dict__ {'color': 'red', 'length': 100} >>> stephens_boat.__class__ <class '__main__.Boat'> The data model in practice
None
class Person(object): weight_kg = 0 @property def weight_lb(self): return self.weight_kg
* 2.2 @weight_lb.setter def weight_lb(self, value): self.weight_kg = value / 2.2 boat.py: Using the data model
None
• https://docs.python.org/2/tutorial/classes.html • https://en.wikipedia.org/wiki/Duck_typing • https://stackoverflow.com/questions/222877/how-to-use-super- in-python • https://docs.python.org/2/reference/datamodel.html