SlideShare a Scribd company logo
Python’s
Dynamic Nature
An investigation of how Python’s dynamic nature
allows it to scale up from one-line scripts to massive
applications.
Kiran Jonnalagadda <jace@seacrow.com>
These are rough slides. The finals will make heavy use
of diagrams in place of text.
What Does
Interpreted Mean?
• Python is not line interpreted like shell
script.

• Python is byte-code compiled like Java,
but compilation is on-the-fly.

• However, Python in some ways behaves
like a line-interpreted language, making
the learning curve easy.
Loading a Module
• When a module (file) is loaded, it is first
compiled into byte-code.

• Python then executes all the code in the
module that is not in a function.

• This code can modify the module as it

loads, making for the line-interpreted feel.

• Code in functions is only executed on call.
Example of Loading
# Example code
print “Top level executes on load.”
def somefunc():
print “Executes only when called.”
class foo:
print “Class level also executes on load.”
def bar(self):
print “Executes only when called.”
Bags of Attributes
• Python is a fully object oriented language.
• All symbols are objects with attributes.
• Objects contain other objects. Therefore,
Python’s namespace is nested.

• A module is an object, a string is an

object, an integer is an object, everything
is an object.
__attributes__
• Python inserts several special attributes
into objects. These attributes are all
named in the __attribute__ style.

• Example 1: __name__ indicates the name
given to the object in code.

• Example 2: __class__ refers to the class
this object is an instance of.
Operator Overloading
• Operator overloading is also achieved via
functions with special attribute names.

• Examples:
• __eq__ and __ne__ for == and !=
• __add__ to add two objects
• __cmp__ to compare, for sorting
Controlling Attribute
Access

• An object can take control of the way its
attributes are accessed.

• The __getitem__ function for list or

dictionary access. Example: object[‘foo’]

• The __getattr__ function for named

access. Example: using object.foo will call
object.__getattr__(‘foo’)

• __setitem__ and __setattr__ for editing.
Documentation
• Python code is self-documenting.
• Documentation can be placed in a string,

which must be the first non-remark
declaration in a module, class or function.

• This documentation is accessible as the
__doc__ attribute of the object.

• Example:

class foo:
“This is the documentation.”
pass
Namespaces
• In Python, everything is contained within
something else.

• The top-level, invisible container is called
__builtins__. Contains internal functions.

• Top-level symbols not from __builtins__
are local symbols.

• Local symbols are not private. They can
be accessed via the namespace.
Namespaces #2
• The top-level namespace is not crowded;

an app can have several modules with
conflicting names and not have a conflict.

• “module1.cname” is different from
“module2.cname”

• Using “name = module1.cname” makes

“name” a local alias for “module1.cname”
Symbols and Objects
• Symbols are not the same as objects.
• Symbols are only references to objects.
• An object can have multiple references.
• Objects are garbage collected when they

have zero references. GC algorithms used
are both reference counting and markand-sweep.
Multiple References
• An module can consist of nothing but

references to symbols in other modules.

• Hence the term, “bags of attributes.”
• This allows a large package to have a

single API module that links to the rest of
the package internally.
References Example
module1.py:
def foo(bar, baz):
return bar + baz

module2.py:
import module1
new_name = module1.foo

module3.py:
from module2 import new_name
print new_name(1, 2)
Runtime Editing
• Python code can edit itself at run-time.
• The only way to define variables in a class
is by editing the instance at runtime.

• Editing involves simply changing the
object a symbol refers to.

• This only works when all code refers to
the object via the symbol, which is the
case almost all the time.
How Classes Work
• {To insert code examples and diagram

here, showing a complex class definition
and how it works when different parts are
accessed. This will be across several
slides.}
Scalability
• Because of the clear namespace

separation, a Python application can
contain thousands of modules without
conflicts.

• Advanced class definition ability helps
avoid repetitive code.

• This makes Python code easy to maintain
and scale, while still remaining simple.
The Type/Class
Dichotomy

• Prior to version 2.2, Python had two
types of objects: Types and Classes.

• Types could only be defined in C code.
• Classes could only be defined in Python.
• Classes could not be derived from Types.
• This meant a base-class could not be
defined externally in C/C++ code.
Zope’s Solution
• Jim Fulton, the creator of Zope, created a
new Type called ExtensionClass.

• ExtensionClass can be derived from, like
a regular Python Class, but is a Type.

• Achieved by patching Python internals.
• ExtensionClass made a lot of extensions

possible that could not be done in Python.
Type/Class Merger
• Python 2.2 merges Types and Classes, so
they are all one type of object.

• But changes are incompatible with

ExtensionClass, which Zope depends on.

• So Zope still uses the old Type/Class

divide, even with Python 2.2 and 2.3.

• Zope will upgrade with Zope 3.

More Related Content

What's hot (20)

KEY
Java Building Blocks
Cate Huston
 
KEY
Thinking Like a Programmer
Cate Huston
 
PPTX
Programming Paradigm & Languages
Gaditek
 
PPT
Virtual Function
Lovely Professional University
 
PDF
Xtend - better java with -less- noise
Neeraj Bhusare
 
PPSX
Short notes of oop with java
Mohamed Fathy
 
PPTX
Introduction to Kotlin for Android developers
Mohamed Wael
 
PPTX
C++vs java
Pradeep wolf king
 
ODP
CORBA & RMI in java
S mahesh acharya
 
DOCX
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
PPT
Constructors and destructors in C++ part 2
Lovely Professional University
 
PPTX
C sharp
Ahmed Vic
 
PPTX
CS8392 OOP
DhanalakshmiVelusamy1
 
PDF
Functional programming with Xtend
Sven Efftinge
 
PDF
Introduction to Clojure
Renzo Borgatti
 
PPT
Presentation On Com Dcom
Bharat Kumar Katur
 
PDF
Ruby Presentation
platico_dev
 
PPT
Corba by Example
Roy Antony Arnold G
 
PPTX
java training in jaipur|java training|core java training|java training compa...
infojaipurinfo Jaipur
 
PPTX
JS - Basics
John Fischer
 
Java Building Blocks
Cate Huston
 
Thinking Like a Programmer
Cate Huston
 
Programming Paradigm & Languages
Gaditek
 
Xtend - better java with -less- noise
Neeraj Bhusare
 
Short notes of oop with java
Mohamed Fathy
 
Introduction to Kotlin for Android developers
Mohamed Wael
 
C++vs java
Pradeep wolf king
 
CORBA & RMI in java
S mahesh acharya
 
Page List & Sample Material (Repaired)
Muhammad Haseeb Shahid
 
Constructors and destructors in C++ part 2
Lovely Professional University
 
C sharp
Ahmed Vic
 
Functional programming with Xtend
Sven Efftinge
 
Introduction to Clojure
Renzo Borgatti
 
Presentation On Com Dcom
Bharat Kumar Katur
 
Ruby Presentation
platico_dev
 
Corba by Example
Roy Antony Arnold G
 
java training in jaipur|java training|core java training|java training compa...
infojaipurinfo Jaipur
 
JS - Basics
John Fischer
 

Viewers also liked (20)

PPTX
Final ppt of gd
Swati Gautam
 
PPT
Group dynamics
Deepthi.R M.S.N
 
PPTX
Group dynamics
Jyothi Chinnasamy
 
PPTX
Group dynamics
Sidharth Benjamin
 
PPT
Group dynamics
Ujjwal 'Shanu'
 
PPTX
Group dynamics
Rohit Kumar
 
PPT
Group Dynamics
Ransom Joseph
 
PPTX
Groups within society
kristinejarabelo
 
PPT
Group dynamics
Shyama Shankar
 
PPTX
Types of Social Groups
Md Aaquib Sahrwardi
 
PPTX
ppt of group dynamics
Swati Gautam
 
PPTX
Danny Maribao_Lesson 3-conformity and obedience
dan_maribao
 
PPTX
Social groups and types
HUMAN Planet earth
 
PPT
Are You Listening? The Importance Of Social Media Monitoring
BFG Communications
 
PPTX
Youth for christ talk 3
Rachellee Mtclro
 
PPT
Importance of group communication
shrutivaghani
 
PPT
Group dynamics
MANISHGONDHALEKAR
 
PPTX
group norms
keshav sharma
 
PPTX
Group dynamics and Ethics
Maymay Lindayao
 
Final ppt of gd
Swati Gautam
 
Group dynamics
Deepthi.R M.S.N
 
Group dynamics
Jyothi Chinnasamy
 
Group dynamics
Sidharth Benjamin
 
Group dynamics
Ujjwal 'Shanu'
 
Group dynamics
Rohit Kumar
 
Group Dynamics
Ransom Joseph
 
Groups within society
kristinejarabelo
 
Group dynamics
Shyama Shankar
 
Types of Social Groups
Md Aaquib Sahrwardi
 
ppt of group dynamics
Swati Gautam
 
Danny Maribao_Lesson 3-conformity and obedience
dan_maribao
 
Social groups and types
HUMAN Planet earth
 
Are You Listening? The Importance Of Social Media Monitoring
BFG Communications
 
Youth for christ talk 3
Rachellee Mtclro
 
Importance of group communication
shrutivaghani
 
Group dynamics
MANISHGONDHALEKAR
 
group norms
keshav sharma
 
Group dynamics and Ethics
Maymay Lindayao
 
Ad

Similar to Python's dynamic nature (rough slides, November 2004) (20)

PPT
UNIT-IV WT web technology for 1st year cs
javed75
 
PDF
Python for katana
kedar nath
 
PPTX
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
PPTX
full defination of final opp.pptx
rayanbabur
 
PPTX
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
sonawaneabhishek69
 
PDF
Owner - Java properties reinvented.
Luigi Viggiano
 
PDF
A peek into Python's Metaclass and Bytecode from a Smalltalk User
Koan-Sin Tan
 
PPTX
Class and Objects in python programming.pptx
Rajtherock
 
PPT
java-corporate-training-institute-in-mumbai
vibrantuser
 
PPT
java-corporate-training-institute-in-mumbai
Unmesh Baile
 
PPT
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
PPTX
Introduction to PHP and MySql basics.pptx
PriyankaKupneshi
 
PPTX
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
PPTX
Functions in Python
Kamal Acharya
 
PPT
Java
Manav Prasad
 
KEY
Programming with Python: Week 1
Ahmet Bulut
 
PDF
Objective-C Is Not Java
Chris Adamson
 
PDF
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
PPT
Java Simple Introduction in single course
binzbinz3
 
UNIT-IV WT web technology for 1st year cs
javed75
 
Python for katana
kedar nath
 
c++.pptxwjwjsijsnsksomammaoansnksooskskk
mitivete
 
full defination of final opp.pptx
rayanbabur
 
Cthhis_is_cybersecurty_and_cyber_sxec.pptx
sonawaneabhishek69
 
Owner - Java properties reinvented.
Luigi Viggiano
 
A peek into Python's Metaclass and Bytecode from a Smalltalk User
Koan-Sin Tan
 
Class and Objects in python programming.pptx
Rajtherock
 
java-corporate-training-institute-in-mumbai
vibrantuser
 
java-corporate-training-institute-in-mumbai
Unmesh Baile
 
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
Introduction to PHP and MySql basics.pptx
PriyankaKupneshi
 
Java programmingjsjdjdjdjdjdjdjdjdiidiei
rajputtejaswa12
 
Functions in Python
Kamal Acharya
 
Programming with Python: Week 1
Ahmet Bulut
 
Objective-C Is Not Java
Chris Adamson
 
web programming UNIT VIII python by Bhavsingh Maloth
Bhavsingh Maloth
 
Java Simple Introduction in single course
binzbinz3
 
Ad

More from Kiran Jonnalagadda (17)

PDF
AirJaldi photo rout (April 2008)
Kiran Jonnalagadda
 
PDF
The medium without the message (April 2008)
Kiran Jonnalagadda
 
PDF
Understanding technology in e-governance (December 2007)
Kiran Jonnalagadda
 
PDF
Namma service cash tracking system (January 2007)
Kiran Jonnalagadda
 
PDF
What ails the Sarai Reader List? (August 2005)
Kiran Jonnalagadda
 
PDF
On blogging as a career (June 2005)
Kiran Jonnalagadda
 
PDF
Python and Zope: An introduction (May 2004)
Kiran Jonnalagadda
 
PDF
Human database relations (March 2004)
Kiran Jonnalagadda
 
PPT
The technology of the Human Protein Reference Database (draft, 2003)
Kiran Jonnalagadda
 
PDF
Introduction to Plone (November 2003)
Kiran Jonnalagadda
 
PDF
ZODB, the Zope Object Database (May 2003)
Kiran Jonnalagadda
 
PDF
XML-RPC and SOAP (April 2003)
Kiran Jonnalagadda
 
ODP
Some dope on Zope (Jan 2002, Bangalore LUG)
Kiran Jonnalagadda
 
PDF
User Management with LastUser
Kiran Jonnalagadda
 
KEY
Sustainability and bit-rot
Kiran Jonnalagadda
 
PDF
e-Governance in Karnataka: An introduction
Kiran Jonnalagadda
 
PDF
Cyberpunk Sci-Fi
Kiran Jonnalagadda
 
AirJaldi photo rout (April 2008)
Kiran Jonnalagadda
 
The medium without the message (April 2008)
Kiran Jonnalagadda
 
Understanding technology in e-governance (December 2007)
Kiran Jonnalagadda
 
Namma service cash tracking system (January 2007)
Kiran Jonnalagadda
 
What ails the Sarai Reader List? (August 2005)
Kiran Jonnalagadda
 
On blogging as a career (June 2005)
Kiran Jonnalagadda
 
Python and Zope: An introduction (May 2004)
Kiran Jonnalagadda
 
Human database relations (March 2004)
Kiran Jonnalagadda
 
The technology of the Human Protein Reference Database (draft, 2003)
Kiran Jonnalagadda
 
Introduction to Plone (November 2003)
Kiran Jonnalagadda
 
ZODB, the Zope Object Database (May 2003)
Kiran Jonnalagadda
 
XML-RPC and SOAP (April 2003)
Kiran Jonnalagadda
 
Some dope on Zope (Jan 2002, Bangalore LUG)
Kiran Jonnalagadda
 
User Management with LastUser
Kiran Jonnalagadda
 
Sustainability and bit-rot
Kiran Jonnalagadda
 
e-Governance in Karnataka: An introduction
Kiran Jonnalagadda
 
Cyberpunk Sci-Fi
Kiran Jonnalagadda
 

Recently uploaded (20)

PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Digital Circuits, important subject in CS
contactparinay1
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Transforming Utility Networks: Large-scale Data Migrations with FME
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 

Python's dynamic nature (rough slides, November 2004)

  • 1. Python’s Dynamic Nature An investigation of how Python’s dynamic nature allows it to scale up from one-line scripts to massive applications. Kiran Jonnalagadda <[email protected]> These are rough slides. The finals will make heavy use of diagrams in place of text.
  • 2. What Does Interpreted Mean? • Python is not line interpreted like shell script. • Python is byte-code compiled like Java, but compilation is on-the-fly. • However, Python in some ways behaves like a line-interpreted language, making the learning curve easy.
  • 3. Loading a Module • When a module (file) is loaded, it is first compiled into byte-code. • Python then executes all the code in the module that is not in a function. • This code can modify the module as it loads, making for the line-interpreted feel. • Code in functions is only executed on call.
  • 4. Example of Loading # Example code print “Top level executes on load.” def somefunc(): print “Executes only when called.” class foo: print “Class level also executes on load.” def bar(self): print “Executes only when called.”
  • 5. Bags of Attributes • Python is a fully object oriented language. • All symbols are objects with attributes. • Objects contain other objects. Therefore, Python’s namespace is nested. • A module is an object, a string is an object, an integer is an object, everything is an object.
  • 6. __attributes__ • Python inserts several special attributes into objects. These attributes are all named in the __attribute__ style. • Example 1: __name__ indicates the name given to the object in code. • Example 2: __class__ refers to the class this object is an instance of.
  • 7. Operator Overloading • Operator overloading is also achieved via functions with special attribute names. • Examples: • __eq__ and __ne__ for == and != • __add__ to add two objects • __cmp__ to compare, for sorting
  • 8. Controlling Attribute Access • An object can take control of the way its attributes are accessed. • The __getitem__ function for list or dictionary access. Example: object[‘foo’] • The __getattr__ function for named access. Example: using object.foo will call object.__getattr__(‘foo’) • __setitem__ and __setattr__ for editing.
  • 9. Documentation • Python code is self-documenting. • Documentation can be placed in a string, which must be the first non-remark declaration in a module, class or function. • This documentation is accessible as the __doc__ attribute of the object. • Example: class foo: “This is the documentation.” pass
  • 10. Namespaces • In Python, everything is contained within something else. • The top-level, invisible container is called __builtins__. Contains internal functions. • Top-level symbols not from __builtins__ are local symbols. • Local symbols are not private. They can be accessed via the namespace.
  • 11. Namespaces #2 • The top-level namespace is not crowded; an app can have several modules with conflicting names and not have a conflict. • “module1.cname” is different from “module2.cname” • Using “name = module1.cname” makes “name” a local alias for “module1.cname”
  • 12. Symbols and Objects • Symbols are not the same as objects. • Symbols are only references to objects. • An object can have multiple references. • Objects are garbage collected when they have zero references. GC algorithms used are both reference counting and markand-sweep.
  • 13. Multiple References • An module can consist of nothing but references to symbols in other modules. • Hence the term, “bags of attributes.” • This allows a large package to have a single API module that links to the rest of the package internally.
  • 14. References Example module1.py: def foo(bar, baz): return bar + baz module2.py: import module1 new_name = module1.foo module3.py: from module2 import new_name print new_name(1, 2)
  • 15. Runtime Editing • Python code can edit itself at run-time. • The only way to define variables in a class is by editing the instance at runtime. • Editing involves simply changing the object a symbol refers to. • This only works when all code refers to the object via the symbol, which is the case almost all the time.
  • 16. How Classes Work • {To insert code examples and diagram here, showing a complex class definition and how it works when different parts are accessed. This will be across several slides.}
  • 17. Scalability • Because of the clear namespace separation, a Python application can contain thousands of modules without conflicts. • Advanced class definition ability helps avoid repetitive code. • This makes Python code easy to maintain and scale, while still remaining simple.
  • 18. The Type/Class Dichotomy • Prior to version 2.2, Python had two types of objects: Types and Classes. • Types could only be defined in C code. • Classes could only be defined in Python. • Classes could not be derived from Types. • This meant a base-class could not be defined externally in C/C++ code.
  • 19. Zope’s Solution • Jim Fulton, the creator of Zope, created a new Type called ExtensionClass. • ExtensionClass can be derived from, like a regular Python Class, but is a Type. • Achieved by patching Python internals. • ExtensionClass made a lot of extensions possible that could not be done in Python.
  • 20. Type/Class Merger • Python 2.2 merges Types and Classes, so they are all one type of object. • But changes are incompatible with ExtensionClass, which Zope depends on. • So Zope still uses the old Type/Class divide, even with Python 2.2 and 2.3. • Zope will upgrade with Zope 3.