16
A Sip of Python in 30 mins. Maher Gamal Cairo-GTUG

A Sip of Python

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: A Sip of Python

A Sip of Python in 30 mins.

Maher Gamal

Cairo-GTUG

Page 2: A Sip of Python

Development Cultures

SAFE

• Follows the big companies

• Must be widely approved

• No chance for risks

EXPLORATORY

• Tries out young technologies

• Mostly self-motivated

• Accepts calculated risks

Page 3: A Sip of Python

How does Python look like ?

>>> print("Welcome everyone !")Welcome everyone !

>>> print("Welcome to %s !" % "GTUG")Welcome to GTUG !

>>> print("%s live in %s !" % ("GTUG", "Cairo"))GTUG live in Cairo !

# Enough with the print statements !# What's next ? Modules !

Page 4: A Sip of Python

How does Python look like ?

>>> import os

>>> os.listdir("/home/maherg")['Documents', 'Pictures', 'Workspaces']

>>> import sys

>>> sys.modules.keys()[ ... 'os', 'time', 'subprocess', ... ]

# Can we write our own module ? Yes, we can !

Page 5: A Sip of Python

How does Python look like ?

# gtug.py: GTUG's schedule

print("Welcome to GTUG's schedule !")

sessions = ['Python',            'AppEngine',            'Hands-on Practice']def list_sessions():    """Prints the sessions for today"""    print("Sessions List:")    for s in sessions:        print("- %s" % s)

Page 6: A Sip of Python

How does Python look like ?

>>> os.listdir(".")['gtug.py']

>>> import gtugWelcome to GTUG's schedule !

>>> gtug.list_sessions()Sessions List:- Python- AppEngine- Hands-on Practice

Page 7: A Sip of Python

How does Python look like ?

# gtug.py: GTUG's schedule

print("Welcome to GTUG's schedule !")

sessions = {'Python' : 'Maher Gamal',            'AppEngine' : 'Amahdy Abdelaziz',            'Hands-on Practice' : 'Everyone'}def list_sessions():    """Prints the sessions for today"""    print("Sessions List:")    for name, speaker in sessions.items():        print("- %s (%s)" % (name, speaker))

Page 8: A Sip of Python

How does Python look like ?

>>> import gtugWelcome to GTUG's schedule !

>>> gtug.list_sessions()Sessions List:- Python (Maher Gamal)- AppEngine (Amahdy Abdelaziz)- Hands-on Practice (Everyone)

>>> # What's next ? Packages !

Page 9: A Sip of Python

How does Python look like ?

# gtug/__init__.py : GTUG's Package Indicator

print("Welcome to GTUG !")

# gtug/schedule.py : GTUG's Schedule Module

>>> import gtugWelcome to GTUG !

>>> import gtug.scheduleWelcome to GTUG's schedule !

>>> gtug.schedule.list_sessions()

Page 10: A Sip of Python

How does Python look like ?

>>> from gtug import scheduleWelcome to GTUG !Welcome to GTUG's schedule !

>>> schedule.list_sessions()...

>>> from gtug.schedule import list_sessions

>>> list_sessions()...# What's next ? Classes !

Page 11: A Sip of Python

How does Python look like ?

# gtug/classes.py : GTUG's classes

class Session():    def __init__(self, title, status = 'none'):        self.title  = title        self.status = status

    def start(self):        self.status = 'started'        def stop(self):        self.status = 'stopped'

Page 12: A Sip of Python

How does Python look like ?

>>> from gtug.classes import Session>>> s = Session('A Sip of Python')

>>> s.start()...>>> s.stop()

>>> Session(status = 'pending', title = '...').start()

Page 13: A Sip of Python

Python's Edges

• Allows multiple paradigms

• Easily readable

• Supports incremental development

• Portable ( Runs on Win/Lin/Mac...etc.) 

• Has loads of community-driven libraries

Page 14: A Sip of Python

Python meets the Web

from google.appengine.ext import webappfrom webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):    def get(self):        self.response.out.write('Main Page')

application =   webapp.WSGIApplication([('/', MainPage)])

run_wsgi_app(application)

Page 15: A Sip of Python

Python Resources

Page 16: A Sip of Python

Stay in Touch

• linkedin : linkedin.com/in/mahergamal

• blog     : maherg.blogspot.com

• email    : [email protected]

• mobile   : 011 351 585 1