Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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
th...
The Zen of Python (PEP* 20)
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex...
Multi paradigm language
Imperative
Object oriented
Functional
Indentation delimits blocks
Python C/C++/Java
if IsOk():
DoThatOne()
DoAnotherOne()
DoFinal()
if ( IsOk() )
{
DoThatOne();...
Modules
import module_name
…
module_name.module_function(...)
module_name.variable
Details: https://docs.python.org/2/tuto...
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 , “...
Immutable objects
Cannot be changed after creation.
Examples: numbers, strings, tuples (the minority)
x = some immutable o...
Immutable objects (2)
>>> x=39
>>> y=x
>>> y=41
>>> print(x)
39
>>> s1='Rob the bank!'
>>> s2=s1
>>> s2='Then take me home...
Mutable objects
Can be changed after creation
Examples: lists, dictionaries, classes (the majority)
x = some mutable objec...
Mutable objects (2)
>>> d1={"Deanna":"Nick Cave", "Jackie":"Placebo"}
>>> d2=d1
>>> d2["Jackie"]="Sinead O'Connor"
>>> pri...
Some popular internal modules
Full list here https://docs.python.org/2.7/py-modindex.html
Coverage:
● process/thread manag...
Some listed here: https://wiki.python.org/moin/UsefulModules
Coverage:
● database handling - sqlalchemy, mysql-python
● GU...
Enough, let’s walk the talk!
Code for this presentation
https://github.com/undergraver/PythonPresentation/
01_intro - some of Python’s characteristics
...
Notes for examples
Please read the documentation for each python module used. Start from [3]
wxpythonUI uses wxpython [5] ...
Notable applications using Python
References
[1] https://developers.google.com/edu/python/
[2] http://www.slideshare.net/amiable_indian/introduction-to-pyth...
Upcoming SlideShare
Loading in …5
×

Python a practical perspective

540 views

Published on

Python presentation with examples available on github. Main concepts can be found by exploring the small and concise code samples available.

It presents some of Python's capabilities and characteristics. The code samples (end of June 2014) are tested with latest Python 2.7 but should be easily convertable to Python 3.

Published in: Travel, Technology
  • Be the first to comment

Python a practical perspective

  1. 1. Python A practical perspective
  2. 2. Purpose Show some Python characteristics Identify scenarios where it can be used Learn by examples
  3. 3. Foreword Using a programming language doesn’t mean knowing everything about it Experiment but focus on the purpose, not the language!
  4. 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/
  5. 5. Multi paradigm language Imperative Object oriented Functional
  6. 6. Indentation delimits blocks Python C/C++/Java if IsOk(): DoThatOne() DoAnotherOne() DoFinal() if ( IsOk() ) { DoThatOne(); DoAnotherOne(); } DoFinal();
  7. 7. Modules import module_name … module_name.module_function(...) module_name.variable Details: https://docs.python.org/2/tutorial/modules.html
  8. 8. Functions def MySum(param1, param2): result = param1 + param2 return result
  9. 9. Classes class Derived(Base): def Method(self,...): … Details: https://docs.python.org/2/tutorial/classes.html
  10. 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. 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. 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. 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. 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. 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. 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. 17. Enough, let’s walk the talk!
  18. 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. 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] )
  20. 20. Notable applications using Python
  21. 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/

×