SlideShare a Scribd company logo
Introduction to Python
Alexander Popov
July 24, 2013 www.ExigenServices.com
2 www.ExigenServices.com
• Who‟s using it?
• Why?
• Overview
• Kind of magic: special keywords
• Decorators
• Samples
• Zen
Presentation index
3 www.ExigenServices.com
Who’s using it?
Sourceforge, Fedora
community
TurboGears
Google, Yahoo, Zope,
Battlefield 2, Vampires:
TM, Civilization 4,
Blender, SGI, Red Hat,
Nokia, Caligari, ABN
AMRO Bank, NASA,
Thawte consulting, IBM,
……
OVER 9000!
Python
Instagram, Pinterest,
Mozilla, The Guardian,
The New York Times, The
Washington Post, Quora
Django
4 www.ExigenServices.com
Why?
5 www.ExigenServices.com
Why Python, not Ruby, Smalltack, Brainf*ck?
• Small core
• 29 keywords, 80 built-in functions
• Elegant syntax
• Embeddable to everything you want
• True cross platform
• Absolutely free
• Extendable (via C++ modules)
• Rich standard library
• Binding almost to everything
6 www.ExigenServices.com
• Fast logic prototyping
• It automates for you mechanical work
• Improves you mind
• Force you to write clear code (on other langs also, sad but true)
• Web development
• Desktop development
• Access to system internal features (WinAPI, Dbus)
• You can find tool for everything.
Why should I spend my time on it instead of beer?
7 www.ExigenServices.com
• Easier than Pascal
• Better than Basic
• Slimmer than PHP
• Prettier than Ruby (empty? empty! empty!! empty!!!!!)
• Does not suffer of abundance of parentheses (((hello) (,) (Lisp!)))
• Pointers? What is it? Ahhhh, it is C++!
• More much dynamic than Java (hello, dynamic typing)
• Improves karma and makes you happy
Wait, what does it means? Really, why?
8 www.ExigenServices.com
• Structural
• OOP
• Functional
• Imperative
• Aspect-oriented
Python paradigms
9 www.ExigenServices.com
Python overview
10 www.ExigenServices.com
• Dynamic (duck) typing
• Variety of basic data types
• Hierarchy marked by indentation
• Code may be grouped to modules
• Exception infrastructure
• Advanced features like generators and list comprehension
• Garbage collector and automatic memory management
Overview: Heap, part 1
11 www.ExigenServices.com
• Function marked by keyword „def‟
• Classes marked by keyword „class‟
• String are immutable
• Special keywords surrounded by
double underscore
• Variables not marked.
Just assign and use.
• Lambda functions
• Object model
Overview: Heap, part 2
12 www.ExigenServices.com
• Do you like objects?
• Class instance is object
• Class definition is object
too.
• Functions. It is objects also.
• Aren‟t you bored of objects?
Elementary types are objects.
• Types… Ok, you know…
• EVERYTHING IS OBJECT!
Everything is object! No exceptions.
13 www.ExigenServices.com
• Just one operator
• Function-powered
variant
• Class example
Hello world
14 www.ExigenServices.com
Class introspection
15 www.ExigenServices.com
• There are matter how to declare
class data members: class-
or instance-wide.
• Class data members
Declared inside class body.
Accessible for all instances
• Instance data members
Declared inside constructor.
Accessible only for one instance.
Class introspection: Members declaration
16 www.ExigenServices.com
• Data members
• Public (no special marks)
• Private-by-convention (started with at least one underscore and
finished with not more than 1 underscore)
• Private-by-mangling (started with 2 underscores and finished
with not more than 1 underscore)
Class introspection: Member access
17 www.ExigenServices.com
• Each class member contains
reference to class object
• Class methods (except static)
are unbound
• Instance methods are bound
• Instance methods may be
called directly
• Class methods may be
called indirectly
Class introspection: Method calls
18 www.ExigenServices.com
• Class definition creation on the fly
• Metaclasses
Class introspection: Fatality
19 www.ExigenServices.com
Sequences
20 www.ExigenServices.com
• Immutable
• String
• Unicode
• Tuple
• Mutable
• List
• Byte Array
• Pseudo sequences
• Sets & frosensets
• Dictionary
Sequences
21 www.ExigenServices.com
List comprehension
22 www.ExigenServices.com
0 1 2 3
[1, 2, 3, 4]
-4 -3 -2 -1
• Index model:
• Indexation
• Indices started from 0
• Indices may be negative
• Slices
• With positive indices
• With negative indices
(be careful with order!)
• With step
Sequences indexation and slicing
23 www.ExigenServices.com
Ranges and generators
24 www.ExigenServices.com
• Ranges
• range( [start], stop, [step] )
• xrange( [start], stop, [step] )
• Generator
Ranges and generators
25 www.ExigenServices.com
Special keywords magic
26 www.ExigenServices.com
• Started and finished with 2 underscore: __foo__
• __call__
• __add__
• __iadd__
• Using special keywords we can emulate any native type:
• Callable (__call__)
• Container (__len__, __getitem__, __setitem__, __delitem__,
__iter__, __reversed__, …)
• Numeric (__add__, __sub__, __mul__, __floordiv__, ...)
Special keywords magic
27 www.ExigenServices.com
Decorators
28 www.ExigenServices.com
• Decorator
• A function that takes one argument
(i.e. the function being decorated)
• Returns the same function or a function
with a similar signature
(i.e. something useful)
• Still WTF? Do not bother,
“what is decorator” is one of most
popular Python questions
Decorators
29 www.ExigenServices.com
• Similar interface
• Similar behavior
• But not the same
Decorators, live
30 www.ExigenServices.com
• Declare the decorator
• Wrap the function
• …
• PROFIT!
• Hey! I want to wrap MY
function!
• Add some magic
• …
• PROFIT again!
Decorators: Wrap the function
31 www.ExigenServices.com
A bit harder…
Decorators: Count function calls
32 www.ExigenServices.com
Decorators: Count function calls, usage
33 www.ExigenServices.com
Meet the Samples
34 www.ExigenServices.com
• Simple HTTP server
python -m SimpleHTTPServer 8888
• SMTP server
python -m smtpd -n -c DebuggingServer localhost:25
• CGI server
python -m CGIHTTPServer 9080
• How many bytes in…
zip(
('Byte','KByte','MByte','GByte',TByte'),
(1 << 10*i for i in xrange(5))
)
• Windows clipboard
import win32clipboard
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()
One-, two- and three-line scripts, part 1
35 www.ExigenServices.com
• Decode base64
import base64, sys;
base64.decode(
open(“encoded.file”, "rb"),
open(“decoded.file”, "wb")
)
• COM
• Test via Python
• Test via VB
One-, two- and three-line scripts, part 2
36 www.ExigenServices.com
Web development
37 www.ExigenServices.com
• Import module Flask
• Create application
• Add route and view
• Run application
Flask micro framework, part 1
38 www.ExigenServices.com
Flask micro framework, part 2
39 www.ExigenServices.com
Flask micro framework, part 3
Alex
40 www.ExigenServices.com
• Fast
• Customizable
• Rich functionality
Templating with Jinja2
41 www.ExigenServices.com
Templating with Jinja2
42 www.ExigenServices.com
• http://docs.python.org/
• http://learnpythonthehardway.org/
• Google Python Days on Youtube
• Coursera:
https://www.coursera.org/course/interactivepython
https://www.coursera.org/course/programming1
• EdX:
https://www.edx.org/courses/MITx/6.00x/2012_Fall/about
• Google, do you speak it?!
• Stackoverflow
• http://www.tornadoweb.org/
• http://www.pylonsproject.org/
• https://www.djangoproject.com/
• http://flask.pocoo.org/
• http://wiki.python.org/moin/PythonDecoratorLibrary
Additional resources
43 www.ExigenServices.com
>>> import this
• Beautiful is better than ugly.
• Explicit is better than implicit.
• Simple is better than complex.
• Complex is better than complicated.
• Flat is better than nested.
• Sparse is better than dense.
• Readability counts.
• Special cases aren't special enough to break the rules.
• Although practicality beats purity.
• Errors should never pass silently.
• Unless explicitly silenced.
to be continued…
The Zen of Python
44 www.ExigenServices.com
>>> import this
• In the face of ambiguity, refuse the temptation to guess.
• There should be one-- and preferably only one --obvious way to
do it.
• Although that way may not be obvious at first unless you're Dutch.
• Now is better than never.
• Although never is often better than *right* now.
• If the implementation is hard to explain, it's a bad idea.
• If the implementation is easy to explain, it may be a good idea.
• Namespaces are one honking great idea -- let's do more of those!
The Zen of Python, part 2
45 www.ExigenServices.com
Afterpaty
46 www.ExigenServices.com
main.py (Create application, initialize database, setup error handlers, Add blueprints)
|=> application1 (account, blog, core)
|=> constants.py (application-wide constants)
|=> forms.py (form used in application)
|=> models.py (database models)
|=> views.py (views)
|=> utils.py
|=> application2
|=> constants.py
|=> forms.py
|=> models.py
|=> views.py
|=> utils.py
…………..
Flask blog code explanation, structure
47 www.ExigenServices.com
Flask blog code explanation, constants
48 www.ExigenServices.com
Flask blog code explanation, forms
49 www.ExigenServices.com
Flask blog code explanation, models
50 www.ExigenServices.com
Flask blog code explanation, views
51 www.ExigenServices.com
Flask blog code explanation, templates
52 www.ExigenServices.com
Thank you!
P.S.: You are fantastic!

More Related Content

What's hot (11)

Ce e nou in Rails 4
Ce e nou in Rails 4Ce e nou in Rails 4
Ce e nou in Rails 4
Florin Oltean
 
Solr Flair: Search User Interfaces Powered by Apache Solr
Solr Flair: Search User Interfaces Powered by Apache SolrSolr Flair: Search User Interfaces Powered by Apache Solr
Solr Flair: Search User Interfaces Powered by Apache Solr
Erik Hatcher
 
Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011
Jesse Warden
 
Real time collaborative text editing, by Miroslav Hettes, Smarkup
Real time collaborative text editing, by Miroslav Hettes, SmarkupReal time collaborative text editing, by Miroslav Hettes, Smarkup
Real time collaborative text editing, by Miroslav Hettes, Smarkup
Smarkup
 
Python assignment help
Python assignment helpPython assignment help
Python assignment help
www.myassignmenthelp.net
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy
 
PHP Classroom Training
PHP Classroom TrainingPHP Classroom Training
PHP Classroom Training
Srihitha Technologies
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection Framework
Adam Warski
 
How to write a web framework
How to write a web frameworkHow to write a web framework
How to write a web framework
Ngoc Dao
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
The ideal module system and the harsh reality
The ideal module system and the harsh realityThe ideal module system and the harsh reality
The ideal module system and the harsh reality
Adam Warski
 
Solr Flair: Search User Interfaces Powered by Apache Solr
Solr Flair: Search User Interfaces Powered by Apache SolrSolr Flair: Search User Interfaces Powered by Apache Solr
Solr Flair: Search User Interfaces Powered by Apache Solr
Erik Hatcher
 
Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011Refactoring RIA Unleashed 2011
Refactoring RIA Unleashed 2011
Jesse Warden
 
Real time collaborative text editing, by Miroslav Hettes, Smarkup
Real time collaborative text editing, by Miroslav Hettes, SmarkupReal time collaborative text editing, by Miroslav Hettes, Smarkup
Real time collaborative text editing, by Miroslav Hettes, Smarkup
Smarkup
 
Clojure in real life 17.10.2014
Clojure in real life 17.10.2014Clojure in real life 17.10.2014
Clojure in real life 17.10.2014
Metosin Oy
 
The no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection FrameworkThe no-framework Scala Dependency Injection Framework
The no-framework Scala Dependency Injection Framework
Adam Warski
 
How to write a web framework
How to write a web frameworkHow to write a web framework
How to write a web framework
Ngoc Dao
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
The ideal module system and the harsh reality
The ideal module system and the harsh realityThe ideal module system and the harsh reality
The ideal module system and the harsh reality
Adam Warski
 

Viewers also liked (20)

English for E-mails
English for E-mailsEnglish for E-mails
English for E-mails
Return on Intelligence
 
Time Management
Time ManagementTime Management
Time Management
Return on Intelligence
 
Profsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by PavelchukProfsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by Pavelchuk
Return on Intelligence
 
Agile Project Grows
Agile Project GrowsAgile Project Grows
Agile Project Grows
Return on Intelligence
 
Windows Azure: Quick start
Windows Azure: Quick startWindows Azure: Quick start
Windows Azure: Quick start
Return on Intelligence
 
Apache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conferenceApache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conference
Return on Intelligence
 
Apache Maven 2 Part 2
Apache Maven 2 Part 2Apache Maven 2 Part 2
Apache Maven 2 Part 2
Return on Intelligence
 
How to develop your creativity
How to develop your creativityHow to develop your creativity
How to develop your creativity
Return on Intelligence
 
Quality Principles
Quality PrinciplesQuality Principles
Quality Principles
Return on Intelligence
 
Non Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic ConditionsNon Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic Conditions
Return on Intelligence
 
Successful interview for a young IT specialist
Successful interview for a young IT specialistSuccessful interview for a young IT specialist
Successful interview for a young IT specialist
Return on Intelligence
 
Large Scale Software Project
Large Scale Software ProjectLarge Scale Software Project
Large Scale Software Project
Return on Intelligence
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
Return on Intelligence
 
Jira as a test management tool
Jira as a test management toolJira as a test management tool
Jira as a test management tool
Return on Intelligence
 
Service design principles and patterns
Service design principles and patternsService design principles and patterns
Service design principles and patterns
Return on Intelligence
 
Risk Management
Risk ManagementRisk Management
Risk Management
Return on Intelligence
 
Principles of personal effectiveness
Principles of personal effectivenessPrinciples of personal effectiveness
Principles of personal effectiveness
Return on Intelligence
 
Cross-cultural communication
Cross-cultural communicationCross-cultural communication
Cross-cultural communication
Return on Intelligence
 
Gradle
GradleGradle
Gradle
Return on Intelligence
 
Resolving conflicts
Resolving conflictsResolving conflicts
Resolving conflicts
Return on Intelligence
 
Profsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by PavelchukProfsoux2014 presentation by Pavelchuk
Profsoux2014 presentation by Pavelchuk
Return on Intelligence
 
Apache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conferenceApache Maven presentation from BitByte conference
Apache Maven presentation from BitByte conference
Return on Intelligence
 
Non Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic ConditionsNon Blocking Algorithms at Traffic Conditions
Non Blocking Algorithms at Traffic Conditions
Return on Intelligence
 
Successful interview for a young IT specialist
Successful interview for a young IT specialistSuccessful interview for a young IT specialist
Successful interview for a young IT specialist
Return on Intelligence
 
Service design principles and patterns
Service design principles and patternsService design principles and patterns
Service design principles and patterns
Return on Intelligence
 
Ad

Similar to Introduction to python (20)

Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
benhurmaarup
 
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
gustyyrauan
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Intermediate python
Intermediate pythonIntermediate python
Intermediate python
NaphtaliOchonogor1
 
Python intro
Python introPython intro
Python intro
rik0
 
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
upendramaurya11
 
обзор Python
обзор Pythonобзор Python
обзор Python
Yehor Nazarkin
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
python learn basic tutorial learn easy..
python learn basic tutorial learn easy..python learn basic tutorial learn easy..
python learn basic tutorial learn easy..
MURTHYVENKAT2
 
Intro
IntroIntro
Intro
Daniel Greenfeld
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
sushil155005
 
Python programming
Python programmingPython programming
Python programming
Keshav Gupta
 
Advance python
Advance pythonAdvance python
Advance python
pulkit agrawal
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
tswr
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
Daniel Greenfeld
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
ParveenShaik21
 
C,s&s
C,s&sC,s&s
C,s&s
sid6376
 
Copy_of_python-journeyman.pdf
Copy_of_python-journeyman.pdfCopy_of_python-journeyman.pdf
Copy_of_python-journeyman.pdf
NedyalkoKarabadzhako
 
Python Demo.pptx
Python Demo.pptxPython Demo.pptx
Python Demo.pptx
ParveenShaik21
 
Best Python tutorial (release 3.7.0)
Best Python tutorial (release 3.7.0)Best Python tutorial (release 3.7.0)
Best Python tutorial (release 3.7.0)
youssef bouferdou
 
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
benhurmaarup
 
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
Dead Simple Python Idiomatic Python for the Impatient Programmer Jason C. Mcd...
gustyyrauan
 
Python Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney
 
Python intro
Python introPython intro
Python intro
rik0
 
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
Luciano Ramalho - Fluent Python_ Clear, Concise, and Effective Programming-O'...
upendramaurya11
 
Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1Introduction to the intermediate Python - v1.1
Introduction to the intermediate Python - v1.1
Andrei KUCHARAVY
 
python learn basic tutorial learn easy..
python learn basic tutorial learn easy..python learn basic tutorial learn easy..
python learn basic tutorial learn easy..
MURTHYVENKAT2
 
Python PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptxPython PPT by Sushil Sir.pptx
Python PPT by Sushil Sir.pptx
sushil155005
 
Python programming
Python programmingPython programming
Python programming
Keshav Gupta
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
tswr
 
Best Python tutorial (release 3.7.0)
Best Python tutorial (release 3.7.0)Best Python tutorial (release 3.7.0)
Best Python tutorial (release 3.7.0)
youssef bouferdou
 
Ad

More from Return on Intelligence (14)

Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
Return on Intelligence
 
Differences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileDifferences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and Agile
Return on Intelligence
 
Windows azurequickstart
Windows azurequickstartWindows azurequickstart
Windows azurequickstart
Return on Intelligence
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обучения
Return on Intelligence
 
Shared position in a project: testing and analysis
Shared position in a project: testing and analysisShared position in a project: testing and analysis
Shared position in a project: testing and analysis
Return on Intelligence
 
Introduction to Business Etiquette
Introduction to Business EtiquetteIntroduction to Business Etiquette
Introduction to Business Etiquette
Return on Intelligence
 
Agile Testing Process
Agile Testing ProcessAgile Testing Process
Agile Testing Process
Return on Intelligence
 
Оценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеОценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработке
Return on Intelligence
 
Meetings arranging
Meetings arrangingMeetings arranging
Meetings arranging
Return on Intelligence
 
The art of project estimation
The art of project estimationThe art of project estimation
The art of project estimation
Return on Intelligence
 
Velocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектомVelocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектом
Return on Intelligence
 
Testing your code
Testing your codeTesting your code
Testing your code
Return on Intelligence
 
Reports Project
Reports ProjectReports Project
Reports Project
Return on Intelligence
 
Business Analyst lecture
Business Analyst lectureBusiness Analyst lecture
Business Analyst lecture
Return on Intelligence
 
Types of testing and their classification
Types of testing and their classificationTypes of testing and their classification
Types of testing and their classification
Return on Intelligence
 
Differences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and AgileDifferences between Testing in Waterfall and Agile
Differences between Testing in Waterfall and Agile
Return on Intelligence
 
Организация внутренней системы обучения
Организация внутренней системы обученияОрганизация внутренней системы обучения
Организация внутренней системы обучения
Return on Intelligence
 
Shared position in a project: testing and analysis
Shared position in a project: testing and analysisShared position in a project: testing and analysis
Shared position in a project: testing and analysis
Return on Intelligence
 
Оценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработкеОценка задач выполняемых по итеративной разработке
Оценка задач выполняемых по итеративной разработке
Return on Intelligence
 
Velocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектомVelocity как инструмент планирования и управления проектом
Velocity как инструмент планирования и управления проектом
Return on Intelligence
 

Recently uploaded (20)

Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
Extend-Microsoft365-with-Copilot-agents.pptx
Extend-Microsoft365-with-Copilot-agents.pptxExtend-Microsoft365-with-Copilot-agents.pptx
Extend-Microsoft365-with-Copilot-agents.pptx
hoang971
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdfTop 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
SOFTTECHHUB
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
AI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never BeforeAI Creative Generates You Passive Income Like Never Before
AI Creative Generates You Passive Income Like Never Before
SivaRajan47
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
Extend-Microsoft365-with-Copilot-agents.pptx
Extend-Microsoft365-with-Copilot-agents.pptxExtend-Microsoft365-with-Copilot-agents.pptx
Extend-Microsoft365-with-Copilot-agents.pptx
hoang971
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdfTop 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
SOFTTECHHUB
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 

Introduction to python

  • 1. Introduction to Python Alexander Popov July 24, 2013 www.ExigenServices.com
  • 2. 2 www.ExigenServices.com • Who‟s using it? • Why? • Overview • Kind of magic: special keywords • Decorators • Samples • Zen Presentation index
  • 3. 3 www.ExigenServices.com Who’s using it? Sourceforge, Fedora community TurboGears Google, Yahoo, Zope, Battlefield 2, Vampires: TM, Civilization 4, Blender, SGI, Red Hat, Nokia, Caligari, ABN AMRO Bank, NASA, Thawte consulting, IBM, …… OVER 9000! Python Instagram, Pinterest, Mozilla, The Guardian, The New York Times, The Washington Post, Quora Django
  • 5. 5 www.ExigenServices.com Why Python, not Ruby, Smalltack, Brainf*ck? • Small core • 29 keywords, 80 built-in functions • Elegant syntax • Embeddable to everything you want • True cross platform • Absolutely free • Extendable (via C++ modules) • Rich standard library • Binding almost to everything
  • 6. 6 www.ExigenServices.com • Fast logic prototyping • It automates for you mechanical work • Improves you mind • Force you to write clear code (on other langs also, sad but true) • Web development • Desktop development • Access to system internal features (WinAPI, Dbus) • You can find tool for everything. Why should I spend my time on it instead of beer?
  • 7. 7 www.ExigenServices.com • Easier than Pascal • Better than Basic • Slimmer than PHP • Prettier than Ruby (empty? empty! empty!! empty!!!!!) • Does not suffer of abundance of parentheses (((hello) (,) (Lisp!))) • Pointers? What is it? Ahhhh, it is C++! • More much dynamic than Java (hello, dynamic typing) • Improves karma and makes you happy Wait, what does it means? Really, why?
  • 8. 8 www.ExigenServices.com • Structural • OOP • Functional • Imperative • Aspect-oriented Python paradigms
  • 10. 10 www.ExigenServices.com • Dynamic (duck) typing • Variety of basic data types • Hierarchy marked by indentation • Code may be grouped to modules • Exception infrastructure • Advanced features like generators and list comprehension • Garbage collector and automatic memory management Overview: Heap, part 1
  • 11. 11 www.ExigenServices.com • Function marked by keyword „def‟ • Classes marked by keyword „class‟ • String are immutable • Special keywords surrounded by double underscore • Variables not marked. Just assign and use. • Lambda functions • Object model Overview: Heap, part 2
  • 12. 12 www.ExigenServices.com • Do you like objects? • Class instance is object • Class definition is object too. • Functions. It is objects also. • Aren‟t you bored of objects? Elementary types are objects. • Types… Ok, you know… • EVERYTHING IS OBJECT! Everything is object! No exceptions.
  • 13. 13 www.ExigenServices.com • Just one operator • Function-powered variant • Class example Hello world
  • 15. 15 www.ExigenServices.com • There are matter how to declare class data members: class- or instance-wide. • Class data members Declared inside class body. Accessible for all instances • Instance data members Declared inside constructor. Accessible only for one instance. Class introspection: Members declaration
  • 16. 16 www.ExigenServices.com • Data members • Public (no special marks) • Private-by-convention (started with at least one underscore and finished with not more than 1 underscore) • Private-by-mangling (started with 2 underscores and finished with not more than 1 underscore) Class introspection: Member access
  • 17. 17 www.ExigenServices.com • Each class member contains reference to class object • Class methods (except static) are unbound • Instance methods are bound • Instance methods may be called directly • Class methods may be called indirectly Class introspection: Method calls
  • 18. 18 www.ExigenServices.com • Class definition creation on the fly • Metaclasses Class introspection: Fatality
  • 20. 20 www.ExigenServices.com • Immutable • String • Unicode • Tuple • Mutable • List • Byte Array • Pseudo sequences • Sets & frosensets • Dictionary Sequences
  • 22. 22 www.ExigenServices.com 0 1 2 3 [1, 2, 3, 4] -4 -3 -2 -1 • Index model: • Indexation • Indices started from 0 • Indices may be negative • Slices • With positive indices • With negative indices (be careful with order!) • With step Sequences indexation and slicing
  • 24. 24 www.ExigenServices.com • Ranges • range( [start], stop, [step] ) • xrange( [start], stop, [step] ) • Generator Ranges and generators
  • 26. 26 www.ExigenServices.com • Started and finished with 2 underscore: __foo__ • __call__ • __add__ • __iadd__ • Using special keywords we can emulate any native type: • Callable (__call__) • Container (__len__, __getitem__, __setitem__, __delitem__, __iter__, __reversed__, …) • Numeric (__add__, __sub__, __mul__, __floordiv__, ...) Special keywords magic
  • 28. 28 www.ExigenServices.com • Decorator • A function that takes one argument (i.e. the function being decorated) • Returns the same function or a function with a similar signature (i.e. something useful) • Still WTF? Do not bother, “what is decorator” is one of most popular Python questions Decorators
  • 29. 29 www.ExigenServices.com • Similar interface • Similar behavior • But not the same Decorators, live
  • 30. 30 www.ExigenServices.com • Declare the decorator • Wrap the function • … • PROFIT! • Hey! I want to wrap MY function! • Add some magic • … • PROFIT again! Decorators: Wrap the function
  • 31. 31 www.ExigenServices.com A bit harder… Decorators: Count function calls
  • 34. 34 www.ExigenServices.com • Simple HTTP server python -m SimpleHTTPServer 8888 • SMTP server python -m smtpd -n -c DebuggingServer localhost:25 • CGI server python -m CGIHTTPServer 9080 • How many bytes in… zip( ('Byte','KByte','MByte','GByte',TByte'), (1 << 10*i for i in xrange(5)) ) • Windows clipboard import win32clipboard win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(text) win32clipboard.CloseClipboard() One-, two- and three-line scripts, part 1
  • 35. 35 www.ExigenServices.com • Decode base64 import base64, sys; base64.decode( open(“encoded.file”, "rb"), open(“decoded.file”, "wb") ) • COM • Test via Python • Test via VB One-, two- and three-line scripts, part 2
  • 37. 37 www.ExigenServices.com • Import module Flask • Create application • Add route and view • Run application Flask micro framework, part 1
  • 39. 39 www.ExigenServices.com Flask micro framework, part 3 Alex
  • 40. 40 www.ExigenServices.com • Fast • Customizable • Rich functionality Templating with Jinja2
  • 42. 42 www.ExigenServices.com • http://docs.python.org/ • http://learnpythonthehardway.org/ • Google Python Days on Youtube • Coursera: https://www.coursera.org/course/interactivepython https://www.coursera.org/course/programming1 • EdX: https://www.edx.org/courses/MITx/6.00x/2012_Fall/about • Google, do you speak it?! • Stackoverflow • http://www.tornadoweb.org/ • http://www.pylonsproject.org/ • https://www.djangoproject.com/ • http://flask.pocoo.org/ • http://wiki.python.org/moin/PythonDecoratorLibrary Additional resources
  • 43. 43 www.ExigenServices.com >>> import this • Beautiful is better than ugly. • Explicit is better than implicit. • Simple is better than complex. • Complex is better than complicated. • Flat is better than nested. • Sparse is better than dense. • Readability counts. • Special cases aren't special enough to break the rules. • Although practicality beats purity. • Errors should never pass silently. • Unless explicitly silenced. to be continued… The Zen of Python
  • 44. 44 www.ExigenServices.com >>> import this • In the face of ambiguity, refuse the temptation to guess. • There should be one-- and preferably only one --obvious way to do it. • Although that way may not be obvious at first unless you're Dutch. • Now is better than never. • Although never is often better than *right* now. • If the implementation is hard to explain, it's a bad idea. • If the implementation is easy to explain, it may be a good idea. • Namespaces are one honking great idea -- let's do more of those! The Zen of Python, part 2
  • 46. 46 www.ExigenServices.com main.py (Create application, initialize database, setup error handlers, Add blueprints) |=> application1 (account, blog, core) |=> constants.py (application-wide constants) |=> forms.py (form used in application) |=> models.py (database models) |=> views.py (views) |=> utils.py |=> application2 |=> constants.py |=> forms.py |=> models.py |=> views.py |=> utils.py ………….. Flask blog code explanation, structure
  • 47. 47 www.ExigenServices.com Flask blog code explanation, constants
  • 48. 48 www.ExigenServices.com Flask blog code explanation, forms
  • 49. 49 www.ExigenServices.com Flask blog code explanation, models
  • 50. 50 www.ExigenServices.com Flask blog code explanation, views
  • 51. 51 www.ExigenServices.com Flask blog code explanation, templates