SlideShare a Scribd company logo
Python
A practical perspective
Purpose
Show some Python characteristics
Identify scenarios where it can be used
Learn by examples
Foreword
Using a programming language doesn’t
mean knowing everything about it
Experiment but focus on the purpose, not
the language!
The Zen of Python (PEP* 20)
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
…
* Python Enhancement Proposal
http://legacy.python.org/dev/peps/pep-0020/
Multi paradigm language
Imperative
Object oriented
Functional
Indentation delimits blocks
Python C/C++/Java
if IsOk():
DoThatOne()
DoAnotherOne()
DoFinal()
if ( IsOk() )
{
DoThatOne();
DoAnotherOne();
}
DoFinal();
Modules
import module_name
…
module_name.module_function(...)
module_name.variable
Details: https://docs.python.org/2/tutorial/modules.html
Functions
def MySum(param1, param2):
result = param1 + param2
return result
Classes
class Derived(Base):
def Method(self,...):
…
Details: https://docs.python.org/2/tutorial/classes.html
Some built-in data types
int, float, long, complex, string, file
Lists: [ 1, “string”, 2.3 ]
Dictionaries: { “Kate”:33 , “John”:25, “Deanna”:42 }
Sets: set([1,2,1,6,7]) → [1,2,6,7]
Tuple: (1, “Nigel”, 23)
Details: https://docs.python.org/2/library/stdtypes.html
Immutable objects
Cannot be changed after creation.
Examples: numbers, strings, tuples (the minority)
x = some immutable object
y = x
y = … # change value of y
x has the same value
Details: https://docs.python.org/2/reference/datamodel.html and Please read [2]
Immutable objects (2)
>>> x=39
>>> y=x
>>> y=41
>>> print(x)
39
>>> s1='Rob the bank!'
>>> s2=s1
>>> s2='Then take me home'
>>> print(s1)
Rob the bank!
>>> s="It's Python, ... yo!"
>>> s[2]='a'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'str' object does not support item assignment
Mutable objects
Can be changed after creation
Examples: lists, dictionaries, classes (the majority)
x = some mutable object
y = x
y = … # change value of y
x has changed its value
Mutable objects (2)
>>> d1={"Deanna":"Nick Cave", "Jackie":"Placebo"}
>>> d2=d1
>>> d2["Jackie"]="Sinead O'Connor"
>>> print(d1)
{'Deanna': 'Nick Cave', 'Jackie': "Sinead O'Connor"}
>>> a1=['The Mono Jacks', 'Grimus', 'Urma']
>>> a2=a1
>>> a2.append('Byron')
>>> print(a1)
['The Mono Jacks', 'Grimus', 'Urma', 'Byron']
Some popular internal modules
Full list here https://docs.python.org/2.7/py-modindex.html
Coverage:
● process/thread management - threading, subprocess
● serialization/persistence - pickle, sqlite3, struct, bsddb, minidom
● network communication - smtplib, poplib, ftplib, sockets, httplib,
urllib2, asyncore
● encoding/compression - bz2, zlib, tarfile, zipfile, base64
● file/directory handling - os, tempfile, os.path, stat
● security - ssl, md5
● string matching/parsing - re, fnmatch, ast
Some listed here: https://wiki.python.org/moin/UsefulModules
Coverage:
● database handling - sqlalchemy, mysql-python
● GUI - wxpython, pyqt
● Scientific/Math functionality - NumPy, SciPy
● Web development - django, web2py
● Image processing - pil, pyqtgraph
● Networking - tornado, twisted, Gevent
● Process listing and manipulation - psutil
Some popular external modules
Enough, let’s walk the talk!
Code for this presentation
https://github.com/undergraver/PythonPresentation/
01_intro - some of Python’s characteristics
02_typical - common Python usages
03_demo - few polished examples
04_regex - regular expressions in Python
Notes for examples
Please read the documentation for each python module used. Start from [3]
wxpythonUI uses wxpython [5] python library + wxformbuilder [7] for ui
design
process list/kill uses psutil [6] python library
For regex is is recommended to read the documentation ( [4] )
Notable applications using Python
References
[1] https://developers.google.com/edu/python/
[2] http://www.slideshare.net/amiable_indian/introduction-to-python
[3] https://docs.python.org/
[4] https://docs.python.org/2/library/re.html
[5] http://www.wxpython.org/
[6] https://code.google.com/p/psutil/
[7] http://sourceforge.net/projects/wxformbuilder/

More Related Content

What's hot

Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camels
miquelruizm
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
Prakash Pimpale
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing Experience
Alexander Gladysh
 
обзор Python
обзор Pythonобзор Python
обзор Python
Yehor Nazarkin
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
Arturo Herrero
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
웅식 전
 
Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
Zaar Hai
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
Ji Hun Kim
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
David de Boer
 
Groovy!
Groovy!Groovy!
Groovy!
Petr Giecek
 
C++ tutorial
C++ tutorialC++ tutorial
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
閒聊Python應用在game server的開發
閒聊Python應用在game server的開發閒聊Python應用在game server的開發
閒聊Python應用在game server的開發
Eric Chen
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
Rodrigo Senra
 
Advanced python
Advanced pythonAdvanced python
Advanced python
EU Edge
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
J David Beutel
 
C++totural file
C++totural fileC++totural file
C++totural file
halaisumit
 
Groovy Fly Through
Groovy Fly ThroughGroovy Fly Through
Groovy Fly Through
niklal
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
Nikita Popov
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
Nikita Popov
 

What's hot (20)

Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camels
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
 
Declarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing ExperienceDeclarative Internal DSLs in Lua: A Game Changing Experience
Declarative Internal DSLs in Lua: A Game Changing Experience
 
обзор Python
обзор Pythonобзор Python
обзор Python
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib3 1. preprocessor, math, stdlib
3 1. preprocessor, math, stdlib
 
Advanced Python, Part 1
Advanced Python, Part 1Advanced Python, Part 1
Advanced Python, Part 1
 
Windbg랑 친해지기
Windbg랑 친해지기Windbg랑 친해지기
Windbg랑 친해지기
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Groovy!
Groovy!Groovy!
Groovy!
 
C++ tutorial
C++ tutorialC++ tutorial
C++ tutorial
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
閒聊Python應用在game server的開發
閒聊Python應用在game server的開發閒聊Python應用在game server的開發
閒聊Python應用在game server的開發
 
pa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processingpa-pe-pi-po-pure Python Text Processing
pa-pe-pi-po-pure Python Text Processing
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
Groovy intro for OUDL
Groovy intro for OUDLGroovy intro for OUDL
Groovy intro for OUDL
 
C++totural file
C++totural fileC++totural file
C++totural file
 
Groovy Fly Through
Groovy Fly ThroughGroovy Fly Through
Groovy Fly Through
 
Opaque Pointers Are Coming
Opaque Pointers Are ComingOpaque Pointers Are Coming
Opaque Pointers Are Coming
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 

Similar to Python a practical perspective

C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debugging
splix757
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Cosimo Streppone
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
Garth Gilmour
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
Tatiana Al-Chueyr
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
ChengHui Weng
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
rik0
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
PyCon Italia
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
krmboya
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
Paris Open Source Summit
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
Joan Puig Sanz
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
niklal
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
GuardSquare
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon Berlin
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
Peter Higgins
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
Deepak Singh
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Rajmahendra Hegde
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 

Similar to Python a practical perspective (20)

C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debugging
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Catch a spider monkey
Catch a spider monkeyCatch a spider monkey
Catch a spider monkey
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Python bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of NairobiPython bootcamp - C4Dlab, University of Nairobi
Python bootcamp - C4Dlab, University of Nairobi
 
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...OWF12/PAUG Conf Days Pro guard   optimizer and obfuscator for android, eric l...
OWF12/PAUG Conf Days Pro guard optimizer and obfuscator for android, eric l...
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
Python utan-stodhjul-motorsag
Python utan-stodhjul-motorsagPython utan-stodhjul-motorsag
Python utan-stodhjul-motorsag
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
 
Cluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in CCluj.py Meetup: Extending Python in C
Cluj.py Meetup: Extending Python in C
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
 
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012Gradle build tool that rocks with DSL JavaOne India 4th May 2012
Gradle build tool that rocks with DSL JavaOne India 4th May 2012
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 

Recently uploaded

Exploring the Majesty of Nepal: An Unforgettable Tour Experience
Exploring the Majesty of Nepal: An Unforgettable Tour ExperienceExploring the Majesty of Nepal: An Unforgettable Tour Experience
Exploring the Majesty of Nepal: An Unforgettable Tour Experience
Welcome Nepal Treks and Tours
 
Discover the Magic of Ibiza An Unforgettable Boat Trip
Discover the Magic of Ibiza An Unforgettable Boat TripDiscover the Magic of Ibiza An Unforgettable Boat Trip
Discover the Magic of Ibiza An Unforgettable Boat Trip
White Island Charter
 
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
River Recreation - Washington Whitewater Rafting
 
Explore Architectural Wonders and Vibrant Culture With Naples Tours
Explore Architectural Wonders and Vibrant Culture With Naples ToursExplore Architectural Wonders and Vibrant Culture With Naples Tours
Explore Architectural Wonders and Vibrant Culture With Naples Tours
Naples Tours
 
Excursions in Tahiti Island Adventure
Excursions in Tahiti Island AdventureExcursions in Tahiti Island Adventure
Excursions in Tahiti Island Adventure
Unique Tahiti
 
bangalore metro routes, stations, timings
bangalore metro routes, stations, timingsbangalore metro routes, stations, timings
bangalore metro routes, stations, timings
narinav14
 
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
eovoam
 
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
CIOWomenMagazine
 
Nature of the task 1. write a paragraph about your trip to dubai and what ar...
Nature of the task  1. write a paragraph about your trip to dubai and what ar...Nature of the task  1. write a paragraph about your trip to dubai and what ar...
Nature of the task 1. write a paragraph about your trip to dubai and what ar...
solutionaia
 
What Challenges Await Beginners in Snowshoeing
What Challenges Await Beginners in SnowshoeingWhat Challenges Await Beginners in Snowshoeing
What Challenges Await Beginners in Snowshoeing
Snowshoe Tahoe
 
Un viaje a Buenos Aires y sus alrededores
Un viaje a Buenos Aires y sus alrededoresUn viaje a Buenos Aires y sus alrededores
Un viaje a Buenos Aires y sus alrededores
Judy Hochberg
 
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.pptDiscovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
Imperial Egypt
 
Understanding Bus Hire ServicesIN MELBOURNE .pptx
Understanding Bus Hire ServicesIN MELBOURNE .pptxUnderstanding Bus Hire ServicesIN MELBOURNE .pptx
Understanding Bus Hire ServicesIN MELBOURNE .pptx
MELBOURNEBUSHIRE
 
How To Change A Name On American Airlines Ticket.pptx
How To Change A Name On American Airlines Ticket.pptxHow To Change A Name On American Airlines Ticket.pptx
How To Change A Name On American Airlines Ticket.pptx
edqour001namechange
 
What Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
What Outdoor Adventures Await Young Adults in Montreal's Surrounding NatureWhat Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
What Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
Spade & Palacio Tours
 
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
Parag Goswami
 
Un viaje a Argentina updated xxxxxxxxxxx
Un viaje a Argentina updated xxxxxxxxxxxUn viaje a Argentina updated xxxxxxxxxxx
Un viaje a Argentina updated xxxxxxxxxxx
Judy Hochberg
 
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdfHow Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
Eastafrica Travelcompany
 
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
yfuwd
 
The Ultimate Travel Guide to Hawaii Island Hopping in 2024
The Ultimate Travel Guide to Hawaii Island Hopping in 2024The Ultimate Travel Guide to Hawaii Island Hopping in 2024
The Ultimate Travel Guide to Hawaii Island Hopping in 2024
adventuressabifn
 

Recently uploaded (20)

Exploring the Majesty of Nepal: An Unforgettable Tour Experience
Exploring the Majesty of Nepal: An Unforgettable Tour ExperienceExploring the Majesty of Nepal: An Unforgettable Tour Experience
Exploring the Majesty of Nepal: An Unforgettable Tour Experience
 
Discover the Magic of Ibiza An Unforgettable Boat Trip
Discover the Magic of Ibiza An Unforgettable Boat TripDiscover the Magic of Ibiza An Unforgettable Boat Trip
Discover the Magic of Ibiza An Unforgettable Boat Trip
 
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
Ready for Cold Weather Rafting Here's What to Wear to Stay Comfortable!
 
Explore Architectural Wonders and Vibrant Culture With Naples Tours
Explore Architectural Wonders and Vibrant Culture With Naples ToursExplore Architectural Wonders and Vibrant Culture With Naples Tours
Explore Architectural Wonders and Vibrant Culture With Naples Tours
 
Excursions in Tahiti Island Adventure
Excursions in Tahiti Island AdventureExcursions in Tahiti Island Adventure
Excursions in Tahiti Island Adventure
 
bangalore metro routes, stations, timings
bangalore metro routes, stations, timingsbangalore metro routes, stations, timings
bangalore metro routes, stations, timings
 
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
定制(cardiff学位证书)英国卡迪夫大学毕业证本科学历原版一模一样
 
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
Golden Gate Bridge: Magnificent Architecture in San Francisco | CIO Women Mag...
 
Nature of the task 1. write a paragraph about your trip to dubai and what ar...
Nature of the task  1. write a paragraph about your trip to dubai and what ar...Nature of the task  1. write a paragraph about your trip to dubai and what ar...
Nature of the task 1. write a paragraph about your trip to dubai and what ar...
 
What Challenges Await Beginners in Snowshoeing
What Challenges Await Beginners in SnowshoeingWhat Challenges Await Beginners in Snowshoeing
What Challenges Await Beginners in Snowshoeing
 
Un viaje a Buenos Aires y sus alrededores
Un viaje a Buenos Aires y sus alrededoresUn viaje a Buenos Aires y sus alrededores
Un viaje a Buenos Aires y sus alrededores
 
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.pptDiscovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
Discovering Egypt A Step-by-Step Guide to Planning Your Trip.ppt
 
Understanding Bus Hire ServicesIN MELBOURNE .pptx
Understanding Bus Hire ServicesIN MELBOURNE .pptxUnderstanding Bus Hire ServicesIN MELBOURNE .pptx
Understanding Bus Hire ServicesIN MELBOURNE .pptx
 
How To Change A Name On American Airlines Ticket.pptx
How To Change A Name On American Airlines Ticket.pptxHow To Change A Name On American Airlines Ticket.pptx
How To Change A Name On American Airlines Ticket.pptx
 
What Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
What Outdoor Adventures Await Young Adults in Montreal's Surrounding NatureWhat Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
What Outdoor Adventures Await Young Adults in Montreal's Surrounding Nature
 
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
5-Day Nathdwara Tour Itinerary: From Temples to Traditional Markets
 
Un viaje a Argentina updated xxxxxxxxxxx
Un viaje a Argentina updated xxxxxxxxxxxUn viaje a Argentina updated xxxxxxxxxxx
Un viaje a Argentina updated xxxxxxxxxxx
 
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdfHow Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
How Do I Plan a Kilimanjaro Climb? 7 Essential Tips Revealed.pdf
 
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
一比一原版(UST毕业证)圣托马斯大学毕业证如何办理
 
The Ultimate Travel Guide to Hawaii Island Hopping in 2024
The Ultimate Travel Guide to Hawaii Island Hopping in 2024The Ultimate Travel Guide to Hawaii Island Hopping in 2024
The Ultimate Travel Guide to Hawaii Island Hopping in 2024
 

Python a practical perspective

  • 2. Purpose Show some Python characteristics Identify scenarios where it can be used Learn by examples
  • 3. Foreword Using a programming language doesn’t mean knowing everything about it Experiment but focus on the purpose, not the language!
  • 4. The Zen of Python (PEP* 20) Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. … * Python Enhancement Proposal http://legacy.python.org/dev/peps/pep-0020/
  • 6. Indentation delimits blocks Python C/C++/Java if IsOk(): DoThatOne() DoAnotherOne() DoFinal() if ( IsOk() ) { DoThatOne(); DoAnotherOne(); } DoFinal();
  • 8. Functions def MySum(param1, param2): result = param1 + param2 return result
  • 9. Classes class Derived(Base): def Method(self,...): … Details: https://docs.python.org/2/tutorial/classes.html
  • 10. Some built-in data types int, float, long, complex, string, file Lists: [ 1, “string”, 2.3 ] Dictionaries: { “Kate”:33 , “John”:25, “Deanna”:42 } Sets: set([1,2,1,6,7]) → [1,2,6,7] Tuple: (1, “Nigel”, 23) Details: https://docs.python.org/2/library/stdtypes.html
  • 11. Immutable objects Cannot be changed after creation. Examples: numbers, strings, tuples (the minority) x = some immutable object y = x y = … # change value of y x has the same value Details: https://docs.python.org/2/reference/datamodel.html and Please read [2]
  • 12. Immutable objects (2) >>> x=39 >>> y=x >>> y=41 >>> print(x) 39 >>> s1='Rob the bank!' >>> s2=s1 >>> s2='Then take me home' >>> print(s1) Rob the bank! >>> s="It's Python, ... yo!" >>> s[2]='a' Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'str' object does not support item assignment
  • 13. Mutable objects Can be changed after creation Examples: lists, dictionaries, classes (the majority) x = some mutable object y = x y = … # change value of y x has changed its value
  • 14. Mutable objects (2) >>> d1={"Deanna":"Nick Cave", "Jackie":"Placebo"} >>> d2=d1 >>> d2["Jackie"]="Sinead O'Connor" >>> print(d1) {'Deanna': 'Nick Cave', 'Jackie': "Sinead O'Connor"} >>> a1=['The Mono Jacks', 'Grimus', 'Urma'] >>> a2=a1 >>> a2.append('Byron') >>> print(a1) ['The Mono Jacks', 'Grimus', 'Urma', 'Byron']
  • 15. Some popular internal modules Full list here https://docs.python.org/2.7/py-modindex.html Coverage: ● process/thread management - threading, subprocess ● serialization/persistence - pickle, sqlite3, struct, bsddb, minidom ● network communication - smtplib, poplib, ftplib, sockets, httplib, urllib2, asyncore ● encoding/compression - bz2, zlib, tarfile, zipfile, base64 ● file/directory handling - os, tempfile, os.path, stat ● security - ssl, md5 ● string matching/parsing - re, fnmatch, ast
  • 16. Some listed here: https://wiki.python.org/moin/UsefulModules Coverage: ● database handling - sqlalchemy, mysql-python ● GUI - wxpython, pyqt ● Scientific/Math functionality - NumPy, SciPy ● Web development - django, web2py ● Image processing - pil, pyqtgraph ● Networking - tornado, twisted, Gevent ● Process listing and manipulation - psutil Some popular external modules
  • 17. Enough, let’s walk the talk!
  • 18. Code for this presentation https://github.com/undergraver/PythonPresentation/ 01_intro - some of Python’s characteristics 02_typical - common Python usages 03_demo - few polished examples 04_regex - regular expressions in Python
  • 19. Notes for examples Please read the documentation for each python module used. Start from [3] wxpythonUI uses wxpython [5] python library + wxformbuilder [7] for ui design process list/kill uses psutil [6] python library For regex is is recommended to read the documentation ( [4] )
  • 21. References [1] https://developers.google.com/edu/python/ [2] http://www.slideshare.net/amiable_indian/introduction-to-python [3] https://docs.python.org/ [4] https://docs.python.org/2/library/re.html [5] http://www.wxpython.org/ [6] https://code.google.com/p/psutil/ [7] http://sourceforge.net/projects/wxformbuilder/