A Sip of Python

733 views
653 views

Published on

An introductory session that given during the Cairo GTUG Meeting #4.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
733
On SlideShare
0
From Embeds
0
Number of Embeds
16
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

A Sip of Python

  1. 1. A Sip of Python in 30 mins. Maher Gamal Ca i ro-GT U G
  2. 2. Development Cultures <ul><li>SAFE </li></ul><ul><ul><li>Follows the big companies </li></ul></ul><ul><ul><li>Must be widely approved </li></ul></ul><ul><ul><li>No chance for risks </li></ul></ul><ul><li>EXPLORATORY </li></ul><ul><ul><li>Tries out young technologies </li></ul></ul><ul><ul><li>Mostly self-motivated </li></ul></ul><ul><ul><li>Accepts calculated risks </li></ul></ul>
  3. 3. How does Python look like ? <ul><li>>>> print ( &quot;Welcome everyone !&quot; ) </li></ul><ul><li>Welcome everyone ! </li></ul><ul><li>>>> print ( &quot;Welcome to %s !&quot; % &quot;GTUG&quot; ) </li></ul><ul><li>Welcome to GTUG ! </li></ul><ul><li>>>> print ( &quot;%s live in %s !&quot; % ( &quot;GTUG&quot; , &quot;Cairo&quot; )) </li></ul><ul><li>GTUG live in Cairo ! </li></ul><ul><li># Enough with the print statements ! </li></ul><ul><li># What's next ? Modules ! </li></ul>
  4. 4. How does Python look like ? <ul><li>>>> import os </li></ul><ul><li>>>> os.listdir( &quot;/home/maherg&quot; ) </li></ul><ul><li>['Documents', 'Pictures', 'Workspaces'] </li></ul><ul><li>>>> import sys </li></ul><ul><li>>>> sys.modules.keys() </li></ul><ul><li>[ ... 'os', 'time', 'subprocess', ... ] </li></ul><ul><li># Can we write our own module ? Yes, we can ! </li></ul>
  5. 5. How does Python look like ? <ul><li># gtug.py: GTUG's schedule </li></ul><ul><li>print ( &quot;Welcome to GTUG's schedule !&quot; ) </li></ul><ul><li>sessions = [ 'Python' , </li></ul><ul><li>             'AppEngine' , </li></ul><ul><li>             'Hands-on Practice' ] </li></ul><ul><li>def list_sessions(): </li></ul><ul><li>     &quot;&quot;&quot;Prints the sessions for today&quot;&quot;&quot; </li></ul><ul><li>     print ( &quot;Sessions List:&quot; ) </li></ul><ul><li>     for s in  sessions: </li></ul><ul><li>         print ( &quot;- %s&quot; % s) </li></ul>
  6. 6. How does Python look like ? <ul><li>>>> os.listdir( &quot;.&quot; ) </li></ul><ul><li>['gtug.py'] </li></ul><ul><li>>>> import gtug </li></ul><ul><li>Welcome to GTUG's schedule ! </li></ul><ul><li>>>> gtug.list_sessions() </li></ul><ul><li>Sessions List: </li></ul><ul><li>- Python </li></ul><ul><li>- AppEngine </li></ul><ul><li>- Hands-on Practice </li></ul>
  7. 7. How does Python look like ? <ul><li># gtug.py: GTUG's schedule </li></ul><ul><li>print ( &quot;Welcome to GTUG's schedule !&quot; ) </li></ul><ul><li>sessions = { 'Python' : 'Maher Gamal' , </li></ul><ul><li>             'AppEngine' : 'Amahdy Abdelaziz' , </li></ul><ul><li>             'Hands-on Practice' : 'Everyone' } </li></ul><ul><li>def list_sessions(): </li></ul><ul><li>     &quot;&quot;&quot;Prints the sessions for today&quot;&quot;&quot; </li></ul><ul><li>     print (&quot; Sessions List:&quot; ) </li></ul><ul><li>     for name, speaker in  sessions.items(): </li></ul><ul><li>         print ( &quot;- %s (%s)&quot; % (name, speaker)) </li></ul>
  8. 8. How does Python look like ? <ul><li>>>> import gtug </li></ul><ul><li>Welcome to GTUG's schedule ! </li></ul><ul><li>>>> gtug.list_sessions() </li></ul><ul><li>Sessions List: </li></ul><ul><li>- Python (Maher Gamal) </li></ul><ul><li>- AppEngine (Amahdy Abdelaziz) </li></ul><ul><li>- Hands-on Practice (Everyone) </li></ul><ul><li>>>> # What's next ? Packages ! </li></ul>
  9. 9. How does Python look like ? <ul><li># gtug/__init__.py : GTUG's Package Indicator </li></ul><ul><li>print ( &quot;Welcome to GTUG !&quot; ) </li></ul><ul><li># gtug/schedule.py : GTUG's Schedule Module </li></ul><ul><li>>>> import gtug </li></ul><ul><li>Welcome to GTUG ! </li></ul><ul><li>>>> import gtug.schedule </li></ul><ul><li>Welcome to GTUG's schedule ! </li></ul><ul><li>>>> gtug.schedule.list_sessions() </li></ul>
  10. 10. How does Python look like ? <ul><li>>>> from gtug import schedule </li></ul><ul><li>Welcome to GTUG ! </li></ul><ul><li>Welcome to GTUG's schedule ! </li></ul><ul><li>>>> schedule.list_sessions() </li></ul><ul><li>... </li></ul><ul><li>>>> from gtug.schedule import list_sessions </li></ul><ul><li>>>> list_sessions() </li></ul><ul><li>... </li></ul><ul><li># What's next ? Classes ! </li></ul>
  11. 11. How does Python look like ? <ul><li># gtug/classes.py : GTUG's classes </li></ul><ul><li>class Session(): </li></ul><ul><li>     def __init__( self , title, status = 'none' ): </li></ul><ul><li>         self.title  = title </li></ul><ul><li>         self.status = status </li></ul><ul><li>     def start( self ): </li></ul><ul><li>         self.status = 'started' </li></ul><ul><li>     </li></ul><ul><li>     def stop( self ): </li></ul><ul><li>         self.status = 'stopped' </li></ul>
  12. 12. How does Python look like ? <ul><li>>>> from gtug.classes import Session </li></ul><ul><li>>>> s = Session( 'A Sip of Python' ) </li></ul><ul><li>>>> s.start() </li></ul><ul><li>... </li></ul><ul><li>>>> s.stop() </li></ul><ul><li>>>> Session(status = 'pending' , title = '...' ).start() </li></ul>
  13. 13. Python's Edges <ul><ul><li>Allows multiple paradigms </li></ul></ul><ul><ul><li>Easily readable </li></ul></ul><ul><ul><li>Supports incremental development </li></ul></ul><ul><ul><li>Portable ( Runs on Win/Lin/Mac...etc.)  </li></ul></ul><ul><ul><li>Has loads of community-driven libraries </li></ul></ul>
  14. 14. Python meets the Web <ul><li>from google.appengine.ext import webapp </li></ul><ul><li>from webapp.util import run_wsgi_app </li></ul><ul><li>class MainPage(webapp.RequestHandler): </li></ul><ul><li>     def get( self ): </li></ul><ul><li>         self .response.out.write( 'Main Page' ) </li></ul><ul><li>application =  </li></ul><ul><li>   webapp.WSGIApplication([( '/' , MainPage)]) </li></ul><ul><li>run_wsgi_app(application) </li></ul>
  15. 15. Python Resources
  16. 16. Stay in Touch <ul><ul><li>linkedin : linkedin.com/in/mahergamal </li></ul></ul><ul><ul><li>blog     : maherg.blogspot.com </li></ul></ul><ul><ul><li>email    : mahergamal@gmail.com </li></ul></ul><ul><ul><li>mobile   : 011 351 585 1 </li></ul></ul>

×