Top Banner
Python 45 Minutes By @AlSayed Gamal
14
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Python 45 minutes hangout #3

Python45

MinutesBy @AlSayed Gamal

Page 2: Python 45 minutes hangout #3

Last Hangout

❖ Data types and containers

❖ Functions

❖ Exceptions

❖ Namespaces and modules

❖ Re-read the sorted list example.

Page 3: Python 45 minutes hangout #3

In This Hangout

❖ Working with files

❖ Reading options passed to your program

❖ Functional programming

❖ Advanced iteration

❖ Debugging tools

Page 4: Python 45 minutes hangout #3

Working With Files

Page 5: Python 45 minutes hangout #3

Working With Files

❖ What’s simpler than open(“path/to/file”) ?

❖ Don’t forget to close the file (finally:)

❖ And even cleaner way use managed context (with:)

❖ File-like objects.

Page 6: Python 45 minutes hangout #3

Reading CL Options

Page 7: Python 45 minutes hangout #3

Reading Options

❖ from optparse import OptionParser

❖ Adding options (short and long), setting default values and errors

❖ using __main__ the entry point.

Page 8: Python 45 minutes hangout #3

Functional Programming

Page 9: Python 45 minutes hangout #3

Functional Programing

❖ Python is a multi-paradigm language (What does that mean?)

❖ Functions are objects and they are first class variables.

❖ Higher order functions

❖ Remember the first hangout example ?

Page 10: Python 45 minutes hangout #3

Functional Programing (2)

❖ Anonymous functions (lambda)

❖ Nested functions (function that defines function)

❖ Closures and “Lexical Scoping” issue.

❖ Operators as functions

❖ Trying doctest.

❖ Decorators and (@notation).

Page 11: Python 45 minutes hangout #3

Advanced Iteration

Page 12: Python 45 minutes hangout #3

Advanced Iteration

❖ List comprehension

❖ Generator expressions

❖ Understanding yield

❖ itertools

❖ zip and izip

Page 13: Python 45 minutes hangout #3

Questions?

Page 14: Python 45 minutes hangout #3

Thank you :)@AlSayed Gamal