Leanpub Header

Skip to main content

1000 Python Examples

The author is letting you choose the price you pay for this book!

Pick Your Price...
PDF
EPUB
WEB
252
Readers
1,069
Pages
About

About

About the Book

Share this book

Price

Pick Your Price...

Minimum price

$7.99

$9.99

You pay

$9.99

Author earns

$7.99
$

All prices are in US $. You can pay in US $ or in your local currency when you check out.

EU customers: prices exclude VAT, which is added during checkout.

...Or Buy With Credits!

Number of credits (Minimum 1)

1
The author will earn $12.00 from your purchase!
You can get credits monthly with a Reader Membership

Author

About the Author

Gábor Szabó

Gábor Szabó has been programming for more than 40 years in a number of languages and in various environments.

These days he usually helps companies improve their engineering practices by providing training, introducing test automation, CI/CD. Sometimes this includes building internal web sites. Gabor also loves explaining things and provides training to his corporate clients and also in the academia.

Gabor runs the Code Maven site and a number of its sub-site where he writes about technologies such as Python, Rust, Git, Continuous Integration, etc.

The first main language Gabor used was Perl and so he maintains the Perl Maven site and he is the chief editor of the Perl Weekly newsletter.

The books Gabor publishes are based on his course materials. They include lots of examples with detailed explanations. This way if you can't book a course with him, at least you can read the materials and learn by yourself.

If you have questions fell free to send him a message via LinkedIn.

Contents

Table of Contents

Fixtures and Mocking in Python

  1. How do you test Moon-landing?
  2. How do you test a system …
  3. Plan
  4. About me
  5. Goal
  6. Fixtures
  7. Fixtuers in Pytest
  8. Traditional xUnit fixtures
  9. Dependency Injection
  10. Temporary directory - tmpdir
  11. Capture STDOUT and STDERR - capsys
  12. Home-made fixture
  13. Home-made fixture - conftest
  14. Home-made fixture with tempdir
  15. Home-made fixture with yield
  16. Fixture Autouse
  17. Fixture Autouse with yield
  18. Fixture for MongoDB
  19. Test Doubles
  20. Test Doubles explained
  21. Verify behavior or state?
  22. What is Mocking and Monkey Patching?
  23. Situations
  24. Unit testing vs. Integration testing
  25. Experiment with mocking in various situations
  26. Examples are simple
  27. Hard coded path
  28. Manually Patching attribute
  29. Monkey Patching attribute
  30. Monkey Patching functions
  31. Monkey Patching dictionary items
  32. Mocking a whole class
  33. Mocking input/output
  34. Mocking input/output
  35. Mocking random numbers
  36. Exercises
  37. Work in pairs
  38. Exercise: test login expiration
  39. Solution: test login expiration
  40. Exercise: Record e-mail sending
  41. Solution: Record e-mail sending
  42. Exercise: Fixture database
  43. Exercise: One Dimentsional space-fight
  44. Exercise: web client
  45. Exercise: Open WeatherMap client
  46. Exercise: Mocking A Bank
  47. Testing the whole application
  48. Resources
  49. Retrospective
  50. Job searching help
  51. Solutions - game
  52. Solutions - Mocking the database access

First steps

  1. What is Python?
  2. What is needed to write a program?
  3. The source (code) of Python
  4. Python 2 vs. Python 3
  5. Installation
  6. Installation on Linux
  7. Installation on Apple Mac OSX
  8. Installation on MS Windows
  9. Editors, IDEs
  10. Documentation
  11. Program types
  12. Python on the command line
  13. First script - hello world
  14. Examples
  15. Comments

marks single line comments.

  1. Variables
  2. Exercise: Hello world
  3. What is programming?
  4. What are the programming languages
  5. A written human language
  6. A programming language
  7. Words and punctuation matter!
  8. Literals, Value Types in Python
  9. Floating point limitation
  10. Value Types in Numpy
  11. Rectangle (numerical operations)
  12. Multiply string
  13. Add numbers
  14. Add strings
  15. Exercise: Calculations
  16. Solution: Calculations

Second steps

  1. Modules
  2. A main function
  3. The main function - called
  4. Indentation
  5. Conditional main
  6. Input - Output I/O
  7. print in Python 2
  8. print in Python 3
  9. print in Python 2 as if it was Python 3
  10. Exception: SyntaxError: Missing parentheses in call
  11. Prompting for user input in Python 2
  12. Prompting for user input in Python 3
  13. Python2 input or raw_input?
  14. Prompting both Python 2 and Python 3
  15. Add numbers entered by the user (oups)
  16. Add numbers entered by the user (fixed)
  17. How can I check if a string can be converted to a number?
  18. Converting string to int
  19. Converting float to int
  20. Conditionals: if
  21. Conditionals: if - else
  22. Divide by 0
  23. Conditionals: if - else (other example)
  24. Conditionals: else if
  25. Conditionals: elif
  26. Ternary operator (Conditional Operator)
  27. Case or Switch in Python
  28. Exercise: Rectangle
  29. Exercise: Calculator
  30. Exercise: Age limit
  31. Exercise: What is this language?
  32. Exercise: Standard Input
  33. Solution: Area of rectangle
  34. Solution: Calculator
  35. Solution: Calculator eval
  36. Solution: Age limit
  37. Solution: What is this language?
  38. Command line arguments
  39. Command line arguments - len
  40. Command line arguments - exit
  41. Exercise: Rectangle (argv)
  42. Exercise: Calculator (argv)
  43. Solution: Area of rectangle (argv)
  44. Solution: Calculator (argv)
  45. Solution: Calculator eval
  46. Compilation vs. Interpretation
  47. Is Python compiled or interpreted?
  48. Flake8 checking
  49. Pylint checking

Numbers

  1. Numbers
  2. Operators for Numbers
  3. Integer division and the future
  4. Pseudo Random Number (unform distribution)
  5. Fixed random numbers
  6. Rolling dice - randrange
  7. Random choice
  8. built-in method
  9. Exception: TypeError: ‘module’ object is not callable
  10. Fixing the previous code
  11. Exception: AttributeError: module ‘random’ has no attribute
  12. Exercise: Number guessing game - level 0
  13. Exercise: Fruit salad
  14. Solution: Number guessing game - level 0
  15. Solution: Fruit salad

Comparison and Boolean

  1. if statement again
  2. Comparison operators
  3. Compare numbers, compare strings
  4. Do NOT Compare different types!
  5. Complex if statement with boolean operators
  6. Boolean operators
  7. Boolean truth tables
  8. Boolean values: True and False
  9. Using True and False in variables
  10. Comparison returns True or False
  11. Assign comparisons to variables
  12. Flag
  13. Toggle
  14. Short circuit
  15. Short circuit fixed
  16. Does this value count as True or False?
  17. True and False values in Python
  18. Incorrect use of conditions
  19. Exercise: compare numbers
  20. Exercise: compare strings
  21. Solution: compare numbers
  22. Solution: compare strings

Strings

  1. Single quoted and double quoted strings
  2. Long lines
  3. Triple quoted strings (multiline)
  4. String length (len)
  5. String repetition and concatenation
  6. A character in a string
  7. String slice (instead of substr)
  8. Change a string
  9. How to change a string
  10. String copy
  11. String functions and methods (len, upper, lower)
  12. index in string
  13. index in string with range
  14. rindex in string with range
  15. find in string
  16. Find all in the string
  17. in string
  18. index if in string
  19. Encodings: ASCII, Windows-1255, Unicode
  20. raw strings
  21. ord
  22. ord in a file
  23. chr - number to character
  24. Exercise: one string in another string
  25. Exercise: to ASCII CLI
  26. Exercise: from ASCII CLI
  27. Solution: one string in another string
  28. Solution: compare strings
  29. Solution: to ASCII CLI
  30. Solution: from ASCII CLI

Loops

  1. Loops: for-in and while
  2. for-in loop on strings
  3. for-in loop on list
  4. for-in loop on range
  5. Iterable, iterator
  6. for in loop with early end using break
  7. for in loop skipping parts using continue
  8. for in loop with break and continue
  9. while loop
  10. Infinite while loop
  11. While with complex expression
  12. While with break
  13. While True
  14. Duplicate input call
  15. Eliminate duplicate input call
  16. do while loop
  17. while with many continue calls
  18. Break out from multi-level loops
  19. Exit vs return vs break and continue
  20. Exercise: Print all the locations in a string
  21. Exercise: Number guessing game
  22. Exercise: Count unique characters
  23. Exercise: Convert for-loop to while-loop
  24. Solution: Print all the locations in a string
  25. Solution 1 for Number Guessing
  26. Solution 2 for Number Guessing (x)
  27. Solution 3 for Number Guessing (s)
  28. Solution for Number Guessing (debug)
  29. Solution for Number Guessing (move)
  30. Solution for Number Guessing (multi-game)
  31. Solution: Count unique characters
  32. Solution: Convert for-loop to while-loop

Formatted printing

  1. format - sprintf
  2. Examples using format - indexing
  3. Examples using format with names
  4. Format columns
  5. Examples using format - alignment
  6. Format - string
  7. Format characters and types
  8. Format floating point number
  9. f-strings (formatted string literals)
  10. printf using old %-syntax
  11. Format braces, bracket, and parentheses
  12. Examples using format with attributes of objects
  13. raw f-strings

Lists

  1. Anything can be a list
  2. Any layout
  3. Lists
  4. List slice with steps
  5. Change a List
  6. Change with steps
  7. List assignment and list copy
  8. Shallow vs. Deep copy of lists
  9. join
  10. join list of numbers
  11. split
  12. for loop on lists
  13. in list
  14. Where is the element in the list
  15. Index improved
  16. [].insert
  17. [].append
  18. [].remove
  19. Remove element by index [].pop
  20. Remove first element of list
  21. Remove several elements of list by index
  22. Use list as a queue
  23. Queue using deque from collections
  24. Fixed size queue
  25. List as a stack
  26. stack with deque
  27. Exercies: Queue
  28. Exercise: Stack
  29. Exercise: MasterMind
  30. Solution: Queue with list
  31. Solution: Queue with deque
  32. Solution: Reverse Polish calculator (stack) with lists
  33. Solution: Reverse Polish calculator (stack) with deque
  34. Solution: MasterMind
  35. MasterMind to debug
  36. Debugging Queue
  37. sort
  38. sort numbers
  39. sort mixed
  40. key sort
  41. sort with sorted
  42. sort vs. sorted
  43. key sort with sorted
  44. Sorting characters of a string
  45. range
  46. Looping over index
  47. Enumerate lists
  48. List operators
  49. List of lists
  50. List assignment
  51. List documentation
  52. tuple
  53. Sort tuples
  54. Exercise: color selector menu
  55. Exercise: count digits
  56. Exercise: Create list
  57. Exercise: Count words
  58. Exercise: Check if number is prime
  59. Exercise: DNA sequencing
  60. Solution: menu
  61. Solution: count digits
  62. Solution: Create list
  63. Solution: Count words
  64. Solution: Check if number is prime
  65. Solution: DNA sequencing
  66. Solution: DNA sequencing with filter
  67. Solution: DNA sequencing with filter and lambda
  68. [].extend
  69. append vs. extend
  70. split and extend

Files

  1. File types: Text vs Binary
  2. Open vs. Read vs. Load
  3. Binary files: Images
  4. Reading an Excel file
  5. Open and read file (easy but not recommended)
  6. Open and read file using with (recommended)
  7. Read file remove newlines
  8. Filename on the command line
  9. Filehandle with return
  10. Read all the lines into a list
  11. Read all the characters into a string (slurp)
  12. Not existing file
  13. Open file exception handling
  14. Open many files - exception handling
  15. Writing to file
  16. Append to file
  17. Binary mode
  18. Does file exist? Is it a file?
  19. Direct access of a line in a file
  20. Exercise: count numbers
  21. Exercise: strip newlines
  22. Exercise: print lines with Report:
  23. Exercise: color selector
  24. Exercise: ROT13
  25. Exercise: Combine lists
  26. Solution: count numbers
  27. Solution: strip newlines
  28. Solution: print lines with Report:
  29. Solution: color selector
  30. Solution: Combine lists
  31. Filehandle using with and not using it

Dictionary (hash)

  1. What is a dictionary
  2. When to use dictionaries
  3. Dictionary
  4. keys
  5. Loop over keys
  6. Loop over dictionary keys
  7. Loop using items
  8. values
  9. Not existing key
  10. Get key
  11. Does the key exist?
  12. Does the value exist?
  13. Delete key
  14. List of dictionaries
  15. Shared dictionary
  16. immutable collection: tuple as dictionary key
  17. immutable numbers: numbers as dictionary key
  18. Sort dictionary by value
  19. Sort dictionary keys by value
  20. Insertion Order is kept
  21. Change order of keys in dictionary - OrderedDict
  22. Set order of keys in dictionary - OrderedDict
  23. Exercise: count characters
  24. Exercise: count words
  25. Exercise: count words from a file
  26. Exercise: Apache log
  27. Exercise: Combine lists again
  28. Exercise: counting DNA bases
  29. Exercise: Count Amino Acids
  30. Exercise: List of dictionaries
  31. Exercise: Dictinoary of dictionaries
  32. Exercise: Age limit with dictionaries
  33. Solution: count characters
  34. Default Dict
  35. Solution: count characters with default dict
  36. Solution: count words
  37. Solution: count words in file
  38. Solution: Apache log
  39. Solution: Combine lists again
  40. Solution: counting DNA bases
  41. Solution: Count Amino Acids
  42. Do not change dictionary in loop

Sets

  1. sets
  2. set operations
  3. Creating a set
  4. Creating an empty set
  5. Adding an element to a set (add)
  6. Merging one set into another set (update)
  7. set intersection
  8. set subset
  9. set symmetric difference
  10. set union
  11. set relative complement

Functions (subroutines)

  1. Why use functions?
  2. Defining simple function
  3. Passing positional parameters to a function
  4. Function parameters can be named
  5. Mixing positional and named parameters
  6. Default values, optional parameters, optional parameters
  7. Default value in first param
  8. Several defaults, using names
  9. Arbitrary number of arguments *
  10. Fixed parmeters before the others
  11. Arbitrary key-value pairs in parameters **
  12. Extra key-value pairs in parameters
  13. Every parameter option
  14. Duplicate declaration of functions (multiple signatures)
  15. Pylint duplicate declaration
  16. Return more than one value
  17. Recursive factorial
  18. Recursive Fibonacci
  19. Non-recursive Fibonacci
  20. Unbound recursion
  21. Variable assignment and change - Immutable
  22. Variable assignment and change - Mutable
  23. Parameter passing of functions
  24. Passing references
  25. Function documentation
  26. Sum ARGV
  27. Copy-paste code
  28. Copy-paste code fixed
  29. Copy-paste code further improvement
  30. Palindrome
  31. Exercise: statistics
  32. Exercise: recursive
  33. Exercise: Tower of Hanoi
  34. Exercise: Merge and Bubble sort
  35. Exercise: Refactor previous solutions to use functions
  36. Solution: statistics
  37. Solution: recursive
  38. Solution: Tower of Hanoi
  39. Solution: Merge and Bubble sort

Modules

  1. Before modules
  2. Create modules
  3. path to load modules from - The module search path
  4. sys.path - the module search path
  5. Flat project directory structure
  6. Absolute path
  7. Relative path
  8. Python modules are compiled
  9. How “import” and “from” work?
  10. Runtime loading of modules
  11. Conditional loading of modules
  12. Duplicate importing of functions
  13. Script or library
  14. Script or library - import
  15. Script or library - from import
  16. assert to verify values
  17. mycalc as a self testing module
  18. doctest
  19. Scope of import
  20. Export import
  21. Export import with all
  22. import module
  23. Execute at import time
  24. Import multiple times
  25. Exercise: Number guessing
  26. Exercies: Scripts and modules
  27. Exercise: Module my_sum
  28. Exercise: Convert your script to module
  29. Exercise: Add doctests to your own code
  30. Solution: Module my_sum

Regular Expressions

  1. What are Regular Expressions (aka. Regexes)?
  2. What are Regular Expressions good for?
  3. Examples
  4. Where can I use it ?
  5. grep
  6. Regexes first match
  7. Match numbers
  8. Capture
  9. Capture more
  10. Capture even more
  11. findall
  12. findall with capture
  13. findall with capture more than one
  14. Any Character
  15. Match dot
  16. Character classes
  17. Common characer classes
  18. Negated character class
  19. Optional character
  20. Regex 0 or more quantifier
  21. Quantifiers
  22. Quantifiers limit
  23. Quantifiers on character classes
  24. Greedy quantifiers
  25. Minimal quantifiers
  26. Anchors
  27. Anchors on both end
  28. Match ISBN numbers
  29. Matching a section
  30. Matching a section - minimal
  31. Matching a section negated character class
  32. DOTALL S (single line)
  33. MULTILINE M
  34. Two regex with logical or
  35. Alternatives
  36. Grouping and Alternatives
  37. Internal variables
  38. More internal variables
  39. Regex DNA
  40. Regex IGNORECASE
  41. Regex VERBOSE X
  42. Substitution
  43. findall capture
  44. Fixing dates
  45. Duplicate numbers
  46. Remove spaces
  47. Replace string in assembly code
  48. Full example of previous
  49. Split with regex
  50. Exercises: Regexes part 1
  51. Exercise: Regexes part 2
  52. Exercise: Sort SNMP numbers
  53. Exercise: parse hours log file and give report
  54. Exercise: Parse ini file
  55. Exercise: Replace Python
  56. Exercise: Extract phone numbers
  57. Solution: Sort SNMP numbers
  58. Solution: parse hours log file and give report
  59. Solution: Processing INI file manually
  60. Solution: Processing config file
  61. Solution: Extract phone numbers
  62. Regular Expressions Cheat sheet
  63. Fix bad JSON
  64. Fix very bad JSON
  65. Raw string or escape
  66. Remove spaces regex
  67. Regex Unicode
  68. Anchors Other example

PyCharm

  1. PyCharm Intro
  2. PyCharm configurations
  3. PyCharm Project
  4. PyCharm Files
  5. PyCharm - run code
  6. PyCharm Python console at the bottom left
  7. Refactoring example with PyCharm

Python standard modules

  1. Some Standard modules
  2. sys
  3. Writing to standard error (stderr)
  4. Current directory (getcwd, pwd, chdir)
  5. OS dir (mkdir, makedirs, remove, rmdir)
  6. python which OS are we running on (os, platform)
  7. Get process ID
  8. OS path
  9. Traverse directory tree - list directories recursively
  10. os.path.join
  11. Directory listing
  12. expanduser - handle tilde ~
  13. Listing specific files using glob
  14. External command with system
  15. subprocess
  16. subprocess in the background
  17. Accessing the system environment variables from Python
  18. Set env and run command
  19. shutil
  20. time
  21. sleep in Python
  22. timer
  23. Current date and time datetime now
  24. Converting string to datetime
  25. datetime arithmeticis
  26. Rounding datetime object to nearest second
  27. Signals and Python
  28. Sending Signal
  29. Catching Signal
  30. Catching Ctrl-C on Unix
  31. Catching Ctrl-C on Unix confirm
  32. Alarm signal and timeouts
  33. deep copy list
  34. deep copy dictionary
  35. Exercise: Catching Ctrl-C on Unix 2nd time
  36. Exercise: Signals
  37. Ctrl-z

JSON

  1. JSON - JavaScript Object Notation
  2. dumps
  3. loads
  4. dump
  5. load
  6. Round trip
  7. Pretty print JSON
  8. Sort keys in JSON
  9. Set order of keys in JSON - OrderedDict
  10. Exercise: Counter in JSON
  11. Exercise: Phone book
  12. Exercise: Processes
  13. Solution: Counter in JSON
  14. Solution: Phone book

Command line arguments with argparse

  1. Modules to handle the command line
  2. argparse
  3. Basic usage of argparse
  4. Positional argument
  5. Many positional argument
  6. Convert to integers
  7. Convert to integer
  8. Named arguments
  9. Boolean Flags
  10. Short names
  11. Exercise: Command line parameters
  12. Exercise: argparse positional and named
  13. argparse print help explicitely
  14. Argparse xor - mutual exlucise - only one - exactly one

Exception handling

  1. Hierarchy of calls
  2. Handling errors as return values
  3. Handling errors as exceptions
  4. A simple exception
  5. Working on a list
  6. Catch ZeroDivisionError exception
  7. Module to open files and calculate something
  8. File for exception handling example
  9. Open files - exception
  10. Handle divide by zero exception
  11. Handle files - exception
  12. Catch all the exceptions and show their type
  13. List exception types
  14. Exceptions
  15. How to raise an exception
  16. Stack trace
  17. Exercies: Exception int conversion
  18. Exercies: Raise Exception
  19. Solution: Exception int conversion (specific)
  20. Solution: Exception int conversion (all other)
  21. Solution: Raise Exception

Classes - OOP - Object Oriented Programming

  1. Why Object Oriented Programming?
  2. Generic Object Oriented Programming terms
  3. OOP in Python
  4. OOP in Python (numbers, strings, lists)
  5. OOP in Python (argparse)
  6. Create a class
  7. Import module containing class
  8. Import class from module
  9. Initialize a class - constructor, attributes
  10. Attributes are not special
  11. Create Point class
  12. Initialize a class - constructor, attributes
  13. Methods
  14. Stringify class
  15. Inheritance
  16. Inheritance - another level
  17. Modes of method inheritance
  18. Modes of method inheritance - implicit
  19. Modes of method inheritance - override
  20. Modes of method inheritance - extend
  21. Modes of method inheritance - delegate - provide
  22. Composition - Line
  23. Some comments
  24. Class in function
  25. Serialization of instances with pickle
  26. Quick Class definition and usage
  27. Exercise: Add move_rad to based on radians
  28. Exercise: Improve previous examples
  29. Exercise: Polygon
  30. Exercise: Number
  31. Exercise: Library
  32. Exercise: Bookexchange
  33. Exercise: Represent turtle graphics
  34. Solution - Polygon

PyPi - Python Package Index

  1. What is PyPi?
  2. Easy Install
  3. pip
  4. Upgrade pip
  5. PYTHONPATH
  6. Virtualenv
  7. Virtualenv for Python 3

SQLite Database Access

  1. SQLite
  2. Connecting to SQLite database
  3. Create TABLE in SQLite
  4. INSERT data into SQLite database
  5. SELECT data from SQLite database
  6. A counter

MySQL

  1. Install MySQL support
  2. Create database user (manually)
  3. Create database (manually)
  4. Create table (manually)
  5. Connect to MySQL
  6. Connect to MySQL and Handle exception
  7. Select data
  8. Select more data
  9. Select all data fetchall
  10. Select some data fetchmany
  11. Select some data WHERE clause
  12. Select into dictionaries
  13. Insert data
  14. Update data
  15. Delete data
  16. Exercise MySQL
  17. Exercise: MySQL Connection
  18. Solution: MySQL Connection

PostgreSQL

  1. PostgreSQL install
  2. Python and Postgresql
  3. PostgreSQL connect
  4. INSERT
  5. INSERT (from command line)
  6. SELECT
  7. DELETE

SQLAlchemy

  1. SQLAlchemy hierarchy
  2. SQLAlchemy engine
  3. SQLAlchemy autocommit
  4. SQLAlchemy engine CREATE TABLE
  5. SQLAlchemy engine INSERT
  6. SQLAlchemy engine SELECT
  7. SQLAlchemy engine SELECT all
  8. SQLAlchemy engine SELECT fetchall
  9. SQLAlchemy engine SELECT aggregate
  10. SQLAlchemy engine SELECT IN
  11. SQLAlchemy engine SELECT IN with placeholders
  12. SQLAlchemy engine connection
  13. SQLAlchemy engine transaction
  14. SQLAlchemy engine using context managers
  15. Exercise: Create table
  16. SQLAlchemy Metada
  17. SQLAlchemy types
  18. SQLAlchemy ORM - Object Relational Mapping
  19. SQLAlchemy ORM create
  20. SQLAlchemy ORM schema
  21. SQLAlchemy ORM reflection
  22. SQLAlchemy ORM INSERT after automap
  23. SQLAlchemy ORM INSERT
  24. SQLAlchemy ORM SELECT
  25. SQLAlchemy ORM SELECT cross tables
  26. SQLAlchemy ORM SELECT and INSERT
  27. SQLAlchemy ORM UPDATE
  28. SQLAlchemy ORM logging
  29. Solution: Create table
  30. Exercise: Inspector
  31. SQLAlchemy CREATE and DROP
  32. SQLAlchemy Notes
  33. SQLAlchemy Meta SQLite CREATE
  34. SQLAlchemy Meta Reflection
  35. SQLAlchemy Meta INSERT
  36. SQLAlchemy Meta SELECT

NoSQL

  1. Types of NoSQL databases

MongoDB

  1. MongoDB CRUD
  2. Install MongoDB support
  3. Python MongoDB insert
  4. MongoDB CLI
  5. Python MongoDB find
  6. Python MongoDB find refine
  7. Python MongoDB update
  8. Python MongoDB remove (delete)
  9. Python MongoDB replace
  10. Python MongoDB upsert
  11. Python Mongodb: TypeError: upsert must be True or False

Redis

  1. Redis CLI
  2. Redis list keys
  3. Redis set get
  4. Redis incr
  5. Redis incrby
  6. Redis setex

Web client

  1. urllib the web client
  2. urllib2 the web client
  3. httpbin.org
  4. requests get
  5. Download image using requests
  6. Download image as a stream using requests
  7. Download zip file
  8. Extract zip file
  9. Interactive Requests
  10. requests get JSON
  11. requests get JSON UserAgent
  12. requests get JSON UserAgent
  13. requests get header
  14. requests change header
  15. requests post
  16. Tweet
  17. API config file
  18. bit.ly
  19. Exercise: Combine web server and client

Python Web server

  1. Hello world web
  2. Dump web environment info
  3. Web echo
  4. Web form
  5. Resources

Python Flask

  1. Python Flask intro
  2. Python Flask installation
  3. Flask: Hello World
  4. Flask: Run Hello World
  5. Flask: testing hello world
  6. Flask generated page - time
  7. Flask generated page - time tested
  8. Flask: Echo GET
  9. Flask: Echo POST
  10. Flask: templates
  11. Flask: templates
  12. Flask: templates with parameters
  13. Flask: runner
  14. Exercise: Flask calculator
  15. Static files
  16. Flask Logging
  17. Flask: Counter
  18. Color selector without session
  19. Session management
  20. Flask custom 404 page
  21. Flask Error page
  22. Flask URL routing
  23. Flask Path params
  24. Flask Path params (int)
  25. Flask Path params add (int)
  26. Flask Path params add (path)
  27. Jinja loop, conditional, include
  28. Exercise: Flask persistent
  29. Exercise: Flask persistent
  30. Flask Exercises
  31. Flask login
  32. Flask JSON API
  33. Flask and AJAX
  34. Flask and AJAX
  35. passlib
  36. Flask Testing
  37. Flask Deploy app
  38. Flask Simple Authentication + test
  39. Flask REST API
  40. Flask REST API - Echo
  41. Flask REST API - parameters in path
  42. Flask REST API - parameter parsing
  43. Flask REST API - parameter parsing - required

Networking

  1. Secure shell
  2. ssh
  3. ssh from Windows
  4. Parallel ssh
  5. telnet
  6. prompt for password
  7. Python nmap
  8. ftp

Interactive shell

  1. The Python interactive shell
  2. REPL - Read Evaluate Print Loop
  3. Using Modules
  4. Getting help
  5. Exercise: Interactive shell

Testing Demo

  1. How do you test your code?
  2. What is testing?
  3. What is testing really?
  4. Testing demo tools
  5. Testing demo methodology
  6. Testing demo - AUT - Application Under Test
  7. Testing demo - use the module
  8. Testing demo: doctest
  9. Testing demo: doctest with failure
  10. Testing demo: Unittest success
  11. Testing demo: Unittest failure
  12. Testing demo: pytest using classes
  13. Testing demo: pytest using classes - failure
  14. Testing demo: pytest without classes
  15. Testing demo: pytest run doctests
  16. Testing demo: pytest run unittest
  17. Exercise: Testing demo
  18. Solution: Testing demo

Types in Python

  1. mypy
  2. Types of variables
  3. Types of function parameters
  4. Types used properly
  5. TODO: mypy

Testing Intro

  1. The software testing equasion
  2. The software testing equasion (fixed)
  3. The pieces of your software?
  4. Manual testing
  5. What to tests?
  6. Continuous Integration

Functional programming

  1. Functional programming
  2. Iterators (Iterables)
  3. range
  4. range with list
  5. range vs. list size
  6. for loop with transformation
  7. map
  8. map delaying function call
  9. map on many values
  10. map with list
  11. double with lambda
  12. What is lambda in Python?
  13. lambda returning tuple
  14. map returning tuples
  15. lambda with two parameters
  16. map for more than one iterable
  17. map on uneven lists
  18. replace None (for Python 2)
  19. map on uneven lists - fixed (for Python 2)
  20. map mixed iterators
  21. map fetch value from dict
  22. Exercise: string to length
  23. Exercise: row to length
  24. Exercise: compare rows
  25. Solution: string to length
  26. Solution: row to length
  27. Solution: compare rows
  28. filter
  29. filter with lambda
  30. filter - map example
  31. filter - map in one expression
  32. Get indexes of values
  33. reduce
  34. reduce with default
  35. zip
  36. Creating dictionary from two lists using zip
  37. all, any
  38. Compare elements of list with scalar
  39. List comprehension - double
  40. List comprehension - simple expression
  41. List generator
  42. List comprehension
  43. Dict comprehension
  44. Lookup table with lambda
  45. Read lines without newlines
  46. Read key-value pairs
  47. Create index-to-value mapping in a dictionary based on a list of values
  48. Exercise: min, max, factorial
  49. Exercise: Prime numbers
  50. Exercise: Many validator functions
  51. Exercise: Calculator using lookup table
  52. Exercise: parse file
  53. Solution: min, max, factorial
  54. Solution: Prime numbers
  55. Solution: Many validator functions
  56. Solution: Calculator using lookup table
  57. map with condtion
  58. map with lambda
  59. map with lambda with condition
  60. List comprehension - complex

Iterators - with and without Itertools

  1. Advantages of iterators and generators
  2. The Fibonacci research institute
  3. Fibonacci plain
  4. Fibonacci copy-paste
  5. Iterators Glossary
  6. What are iterators and iterables?
  7. A file-handle is an iterator
  8. range is iterable but it is not an iterator
  9. Iterator: a counter
  10. Using iterator
  11. Iterator without temporary variable
  12. The type of the iterator
  13. Using iterator with next
  14. Mixing for and next
  15. Iterable which is not an iterator
  16. Iterator returning multiple values
  17. Range-like iterator
  18. Unbound or infinite iterator
  19. Unbound iterator Fibonacci
  20. Operations on Unbound iterator
  21. itertools
  22. itertools - count
  23. itertools - cycle
  24. Exercise: iterators - reimplement the range function
  25. Exercise: iterators - cycle
  26. Exercise: iterators - alter
  27. Exercise: iterators - limit Fibonacci
  28. Exercise: iterators - Fibonacci less memory
  29. Exercise: read char
  30. Exercise: read section
  31. Exercise: collect packets
  32. Exercise: compare files
  33. Solution: iterators - limit Fibonacci
  34. Solution: iterators - Fibonacci less memory
  35. Solution: read section
  36. Solution: compare files
  37. Solution: collect packets

Generators and Generator Expressions

  1. Generators Glossary
  2. Iterators vs Generators
  3. List comprehension and Generator Expression
  4. List comprehension vs Generator Expression - less memory
  5. List comprehension vs Generator Expression - lazy evaluation
  6. Generator: function with yield - call next
  7. Generators - call next
  8. Generator with yield
  9. Generators - fixed counter
  10. Generators - counter
  11. Generators - counter with parameter
  12. Generators - my_range
  13. Fibonacci - generator
  14. Infinite series
  15. Integers
  16. Integers + 3
  17. Integers + Integers
  18. Filtered Fibonacci
  19. The series.py
  20. generator - unbound count (with yield)
  21. iterator - cycle
  22. Exercise: Alternator
  23. Exercise: Prime number generator
  24. Exercise: generator
  25. Exercise: Tower of Hanoi
  26. Exercise: Binary file reader
  27. Exercise: File reader with records

Logging

  1. Simple logging
  2. Simple logging - set level
  3. Simple logging to a file
  4. Simple logging format
  5. Simple logging change date format
  6. getLogger
  7. Time-based logrotation
  8. Size-based logrotation

Closures

  1. Counter local - not working
  2. Counter with global
  3. Create incrementors
  4. Create internal function
  5. Create function by a function
  6. Create function with parameters
  7. Counter closure
  8. Make incrementor with def (closure)
  9. Make incrementor with lambda
  10. Exercise: closure bank
  11. Solution: closure bank
  12. Solution: counter with parameter

Decorators

  1. Function assignment
  2. Function inside other function
  3. Decorator
  4. Use cases for decorators in Python
  5. A recursive Fibonacci
  6. trace fibo
  7. tron decorator
  8. Decorate with direct call
  9. Decorate with parameter
  10. Decorator accepting parameter
  11. Decorate function with any signature
  12. Decorate function with any signature - implementation
  13. Exercise: Logger decorator
  14. Exercise: memoize decorator
  15. Solution: Logger decorator
  16. Solution: Logger decorator (testing)
  17. Solution memoize decorator

Context managers (with statement)

  1. Why use context managers?
  2. Context Manager examples
  3. cd in a function
  4. open in function
  5. open in for loop
  6. open in function using with
  7. Plain context manager
  8. Param context manager
  9. Context manager that returns a value
  10. Use my tempdir - return
  11. Use my tempdir - exception
  12. cwd context manager
  13. tempdir context manager
  14. Context manager with class
  15. Context managers with class
  16. Context manager: with for file
  17. With - context managers
  18. Exercise: Context manager
  19. Exercise: Tempdir on Windows
  20. Solution: Context manager

Advanced lists

  1. Change list while looping: endless list
  2. Change list while looping
  3. Copy list before iteration
  4. for with flag
  5. for else
  6. enumerate
  7. do while
  8. list slice is copy

Advanced Exception handling

  1. Exceptions else
  2. Exceptions finally
  3. Exit and finally
  4. Catching exceptions
  5. Home made exception
  6. Home made exception with attributes
  7. Home made exception hierarcy
  8. Home made exception hierarcy - 1
  9. Home made exception hierarcy - 2
  10. Home made exception hierarcy - 3
  11. Exercise: spacefight with exceptions
  12. Exercies: Raise My Exception
  13. Solution: spacefight with exceptions
  14. Solution: Raise My Exception
  15. Exception finally return

Warnings

  1. Warnings

CSV

  1. Reading CSV the naive way
  2. CSV with quotes and newlines
  3. Reading a CSV file
  4. CSV dialects
  5. CSV to dictionary
  6. Exercise: CSV
  7. Solution: CSV

Excel

  1. Spreadsheets
  2. Python Excel
  3. Create an Excel file from scratch
  4. Worksheets in Excel
  5. Add expressions to Excel
  6. Format field
  7. Number series and chart
  8. Read Excel file
  9. Update Excel file
  10. Exercise: Excel

XML

  1. XML Data
  2. Expat - Callbacks
  3. XML DOM - Document Object Model
  4. XML SAX - Simple API for XML
  5. SAX collect
  6. XML elementtree

SciPy - for Scientific Computing in Python

  1. Data Science tools in Python
  2. Data Analysis resources

Python and Biology

  1. Biopython
  2. Biopython background
  3. Bio python sequences
  4. Download data
  5. Read FASTA, GenBank files
  6. Search nucleotids
  7. Download nucleotids
  8. Exercise: Nucleotid
  9. Biology background

Chemistry

  1. Chemistry links
  2. Bond length
  3. Covalent radius
  4. Python energy landscape explorer
  5. Other chemistry links

numpy

  1. What is NumPy
  2. Numpy - vector
  3. NumPy 2D arrays
  4. Numpy - set type
  5. NumPy arrays: ones and zeros
  6. Numpy: eye
  7. NumPy array random
  8. NumPy Random integers
  9. NumPy array type change by division (int to float)
  10. Numpy: Array methods: transpose
  11. Numpy: reference, not copy
  12. Numpy: copy array
  13. Numpy: Elementwise Operations on Arrays
  14. Numpy: multiply, matmul, dot for vectors
  15. Numpy: multiply, matmul, dot for vector and matrix
  16. Numpy: multiply, matmul, dot for matrices
  17. Numpy: casting - converting from strings to integer.
  18. Numpy: indexing 1d array
  19. Numpy: slice is a reference
  20. Numpy: slice - copy
  21. Numpy: abs value on a Numpy array
  22. Numpy: Logical not on a Numpy array
  23. Numpy: Vectorize a function
  24. Numpy: Vectorize len
  25. Numpy: Vectorize lambda
  26. Numpy: Filtering array
  27. Numpy: Filter matrix values
  28. Numpy: Filter matrix rows
  29. Numpy: Stat
  30. Numpy: Serialization
  31. Numpy: Load from Matlab file
  32. Numpy: Save as Matlab file
  33. Numpy: Horizontal stack vectors (hstack)
  34. Numpy: Append or vertically stack vectors and matrices (vstack)
  35. Numpy uint8
  36. Numpy int8

Pandas

  1. Pandas
  2. Planets
  3. Pandas Planets - Dataframes
  4. Pandas Stocks
  5. Pandas Stocks
  6. Merge Dataframes
  7. Analyze Alerts
  8. Analyze IFMetrics
  9. Create Excel file for experiment with random data
  10. Calculate Genome metrics
  11. Calculate Genome metrics - add columns
  12. Calculate Genome metrics - vectorized
  13. Calculate Genome metrics - vectorized numpy
  14. Genes using Jupyter
  15. Combine columns
  16. Pandas more
  17. Pandas Series
  18. Pandas Series with names

Matplotlib

  1. About Matplotlib
  2. Matplotlib Line
  3. Matplotlib Line with dates
  4. Matplotlib Simple Pie
  5. Matplotlib Simple Pie with params
  6. Matplotlib Pie
  7. Matplotlib Pie 2
  8. Plot, scatter, histogram

Seaborn

  1. Searborn use examples
  2. Seaborn tip
  3. Seaborn Anscombes Quartet

Jupyter notebooks

  1. Jupyter on Windows
  2. Jupyter on Linux and OSX
  3. Jupyter add
  4. Planets
  5. Jupyter notebook Planets
  6. Jupyter StackOverflow
  7. Jupyter StackOverflow - selected columns
  8. Jupyter processing chunks
  9. Jupyter StackOverflow - selected rows
  10. Jupyter StackOverflow - biggest countries (in terms of number of responses)
  11. Jupyter StackOverflow - historgram
  12. Jupyter StackOverflow - filter by country
  13. Jupyter StackOverflow - OpenSourcer
  14. Jupyter StackOverflow - cross tabulation
  15. Jupyter StackOverflow - salaries
  16. Jupyter StackOverflow - replace values
  17. Jupyter StackOverflow - selected rows
  18. Jupyter notebook Intellisense (TAB completition)
  19. Jupyter examples
  20. IPy Widgets

Testing

  1. Traditional Organizations
  2. Quality Assurance
  3. Web age Organizations
  4. TDD vs Testing as an Afterthought
  5. Why test?
  6. Testing Modes
  7. Testing Applications
  8. Testing What to test?
  9. Testing in Python
  10. Testing Environment
  11. Testing Setup - Fixture
  12. Testing Resources

Testing with unittest

  1. Use a module
  2. Test a module
  3. The tested module
  4. Testing - skeleton
  5. Testing
  6. Test examples

Testing with PyTest

  1. Pytest features
  2. Pytest setup
  3. Testing with Pytest
  4. Testing functions
  5. Testing class and methods
  6. Pytest - execute
  7. Pytest - execute
  8. Pytest simple module to be tested
  9. Pytest simple tests - success
  10. Pytest simple tests - success output
  11. Pytest simple tests - failure
  12. Pytest simple tests - failure output
  13. Exercise: test math functions
  14. Exercise: test this app
  15. Exercise: test the csv module
  16. Solution: Pytest test math functions
  17. Solution: Pytest test this app
  18. Solution: test the csv module
  19. PyTest bank deposit
  20. PyTest expected exceptions (bank deposit)
  21. PyTest expected exceptions (bank deposit) - no exception happens
  22. PyTest expected exceptions (bank deposit) - different exception is raised
  23. PyTest expected exceptions
  24. PyTest expected exceptions output
  25. PyTest expected exceptions (text changed)
  26. PyTest expected exceptions (text changed) output
  27. PyTest expected exceptions (other exception)
  28. PyTest expected exceptions (other exception) output
  29. PyTest expected exceptions (no exception)
  30. PyTest expected exceptions (no exception) output
  31. PyTest: Multiple Failures
  32. PyTest: Multiple Failures output
  33. PyTest Selective running of test functions
  34. PyTest: stop on first failure
  35. Pytest: expect a test to fail (xfail or TODO tests)
  36. Pytest: expect a test to fail (xfail or TODO tests)
  37. PyTest: show xfailed tests with -rx
  38. Pytest: skipping tests
  39. Pytest: show skipped tests woth -rs
  40. Pytest: show extra test summmary info with -r
  41. Pytest: skipping tests output in verbose mode
  42. Pytest verbose mode
  43. Pytest quiet mode
  44. PyTest print STDOUT and STDERR using -s
  45. PyTest failure reports
  46. PyTest compare numbers
  47. PyTest compare numbers relatively
  48. PyTest compare strings
  49. PyTest compare long strings
  50. PyTest is one string in another strings
  51. PyTest test any expression
  52. PyTest element in list
  53. PyTest compare lists
  54. PyTest compare short lists
  55. PyTest compare short lists - verbose output
  56. PyTest compare dictionaries
  57. PyTest compare dictionaries output
  58. PyTest Fixtures
  59. PyTest Fixture setup and teardown
  60. PyTest Fixture setup and teardown output
  61. PyTest: Class setup and teardown
  62. PyTest: Class setup and teardown output
  63. Pytest Dependency injection
  64. Pytest fixture - tmpdir
  65. Pytest capture STDOUT and STDERR with capsys
  66. Pytest Fixture - home made fixtures
  67. More fixtures
  68. Pytest: Mocking - why?
  69. Pytest: Mocking - what?
  70. Pytest: One dimensional spacefight
  71. Pytest: Mocking input and output
  72. Pytest: Mocking random
  73. Pytest: Flask echo
  74. Pytest: testing Flask echo
  75. PyTest: Run tests in parallel with xdist
  76. PyTest: Order of tests
  77. PyTest: Randomize Order of tests
  78. PyTest: Force default order
  79. PyTest: no random order
  80. Anagram on the command line
  81. PyTest testing CLI
  82. PyTest test discovery
  83. PyTest test discovery - ignore some tests
  84. PyTest select tests by name
  85. PyTest select tests by marker
  86. PyTest: Test Coverage
  87. Exercise: module
  88. Exercise: Open Source
  89. Pytest resources
  90. Pytest and tempdir
  91. PyTest compare short lists - output
  92. PyTest with parameter
  93. PyTest with parameters
  94. Pytest reporting in JUnit XML format
  95. No test selected

Advancted functions

  1. Variable scopes
  2. Name resolution order (LEGB)
  3. Scoping: global seen from fuction
  4. Assignment creates local scope
  5. Local scope gone wrong
  6. Changing global variable from a function
  7. Global variables mutable in functions
  8. Scoping issues
  9. sub in sub
  10. Scoping sub in sub (enclosing scope)
  11. Function objects
  12. Functions are created at run time
  13. Mutable default
  14. Use None as default parameter
  15. Inner function created every time the outer function runs
  16. Static variable
  17. Static variable in generated function
  18. Inspect

Variable number of function arguments

  1. Python function arguments - a reminder
  2. Functions with unknown number of argumerns
  3. Variable length argument list with * and **
  4. Passing arguments as they were received (but incorrectly)
  5. Unpacking args before passing them on
  6. Exercise: implement the my_sum function
  7. Solution: implement the my_sum function
  8. Exercise: implement the reduce function
  9. Soluton: implement the reduce function
  10. Exercise: sort pairs
  11. Solution: sort pairs

Python Packages

  1. Why Create package
  2. Create package
  3. Internal usage
  4. use module in package - relative path
  5. use package (does not work)
  6. package importing (and exporting) module
  7. use package (module) with import
  8. use package with import
  9. Creating an installable Python package
  10. Create tar.gz file
  11. Install Package
  12. Dependencies
  13. Add README file
  14. Add README file (setup.py)
  15. Include executables
  16. Add tests
  17. Add tests calc
  18. Add tests all
  19. setup.py
  20. Run tests and create package
  21. Packaging applications (creating executable binaries)
  22. Using PyInstaller
  23. Other PyInstaller examples
  24. Other
  25. Py2app for Mac
  26. Exercise: package
  27. Exercise: create executable

Ctypes

  1. ctypes - hello
  2. concat
  3. links

Advanced OOP

  1. Class count instances
  2. Class Attributes
  3. Class Attributes in Instances
  4. Attributes with method access
  5. Instance Attribute
  6. Methods are class attributes
  7. Monkey patching
  8. Classes: instance method
  9. Class methods and class attributes
  10. Classes: constructor
  11. Class methods - alternative constructor
  12. Abstract Base Class
  13. Abstract Base Class with abc
  14. ABC working example
  15. ABC - cannot instantiate the base-class
  16. ABC - must implement methods
  17. Use Python @propery to fix bad interface (the bad interface)
  18. Use Python @propery to fix bad interface (first attempt)
  19. Use Python @propery to fix bad API
  20. Use Python @propery decorator to fix bad API
  21. Use Python @propery for value validation
  22. class and static methods
  23. Destructor: del
  24. Destructor delayed
  25. Destructor delayed for both
  26. Opearator overloading
  27. Operator overloading methods
  28. Exercise: rectangular
  29. Exercise: SNMP numbers
  30. Exercise: Implement a Gene inheritance model combining DNA
  31. Exercise: imaginary numbers - complex numbers
  32. Solution: Rectangular
  33. Solution: Implement a Gene inheritance model combining DNA
  34. Instance counter

2to3

  1. Convertig from Python 2 to Python 3
  2. division
  3. print in Python 2
  4. print in Python 3
  5. input and raw_input
  6. Code that works on both 2 and 3
  7. Compare different types
  8. Octal numbers
  9. 2to3 Resources

Design Patterns

  1. What are Design Patterns?
  2. Don’t replace built-in objects
  3. Facade - simple interface to complex system
  4. Monkey Patching
  5. Creation DPs “Just One”
  6. Singleton
  7. Monostate (Borg)
  8. Dispatch table

Parallel

  1. Types of Problems
  2. Types of solutions
  3. How many parallels to use?
  4. Dividing jobs
  5. Performance Monitoring

Threads

  1. Python Threading docs
  2. Threaded counters
  3. Simple threaded counters
  4. Simple threaded counters (parameterized)
  5. Pass parameters to threads - Counter with attributes
  6. Create a central counter
  7. Lock - acquire - release
  8. Counter - plain
  9. GIL - Global Interpreter Lock
  10. Thread load
  11. Exercise: thread files
  12. Exercise: thread URL requests.
  13. Exercise: thread queue
  14. Solution: thread queue
  15. Solution: thread URL requests.

Forking

  1. Fork
  2. Forking
  3. Fork skeleton
  4. Fork with load
  5. Fork load results
  6. Marshalling / Serialization
  7. Fork with random
  8. Exercise: fork return data
  9. Solution: fork return data

Asyncronus programming with AsyncIO

  1. Sync chores
  2. Async chores
  3. Explanation
  4. Coroutines
  5. More about asyncio
  6. Async files

Asynchronus programming with Twisted

  1. About Twisted
  2. Echo
  3. Echo with log
  4. Simple web client
  5. Web client

Multiprocess

  1. Multiprocess CPU count
  2. Multiprocess Process
  3. Multiprocess N files: Pool
  4. Multiprocess load
  5. Multiprocess: Pool
  6. Multiprocess load async
  7. Multiprocess and logging
  8. Exercise: Process N files in parallel
  9. Exercise: Process N Excel files in parallel
  10. Exercise: Fetch URLs in parallel
  11. Exercise: Fetch URLs from one site.
  12. Solution: Fetch URLs in parallel

Multitasking

  1. What is Multitasking?
  2. Multitasking example
  3. Multitasking example with wait
  4. Multitaksing - second loop waits for first one
  5. Multitasking counter
  6. Multitasking counter with thread locking

Improving Performance - Optimizing code

  1. Problems
  2. Optimization strategy
  3. Locate the source of the problem
  4. Optimizing tactics
  5. DSU: Decorate Sort Undecorate
  6. Profile code
  7. Slow example
  8. profile slow code
  9. cProfile slow code
  10. Benchmarking
  11. Benchmarking subs
  12. Levenshtein distance
  13. Generate words
  14. Levenshtein - pylev
  15. Levenshtein - editdistance
  16. Editdistance benchmark
  17. A Tool to Generate text files
  18. Count characters
  19. Memory leak
  20. Garbage collection
  21. Weak reference
  22. Exercise: benchmark list-comprehension, map, for
  23. Exercise: Benchmark Levenshtein
  24. Exercise: sort files
  25. Exercise: compare split words:
  26. Exercise: count words

GUI with Python/Tk

  1. Sample Tk app
  2. GUI Toolkits
  3. Installation
  4. Python Tk Documentation
  5. Python Tk Button
  6. Python Tk Button with action
  7. Python Tk Label
  8. Python Tk Label - font size and color
  9. Python Tk Keybinding
  10. Python Tk Entry (one-line text entry)
  11. Python Tk Entry for passwords and other secrets (hidden text)
  12. Python Tk Checkbox
  13. Python Tk Radiobutton
  14. Python Tk Listbox
  15. Python Tk Listbox Multiple
  16. Python Tk Menubar
  17. Python Tk Text
  18. Python Tk Dialogs
  19. Python Tk Filedialog
  20. Python Tk messagebox
  21. Python Tk Combobox
  22. Python Tk OptionMenu
  23. Python Tk Scale
  24. Python Tk Progressbar
  25. Python Tk Frame
  26. Not so Simple Tk app with class
  27. Tk: Hello World
  28. Tk: Quit button
  29. Tk: File selector
  30. Tk: Checkbox
  31. Tk: Runner
  32. Tk: Runner with threads
  33. Getting started with Tk
  34. Exercise: Tk - Calculator one line
  35. Exercise: Tk Shopping list
  36. Exercise: Tk TODO list
  37. Exercise: Tk Notepad
  38. Exercise: Tk Copy files
  39. Exercise: Tk Implement Master Mind board
  40. Exercise: Tk
  41. Solution: Tk - Calculator one line
  42. Solution: Tk Implement Master Mind board
  43. Solution: Tk
  44. Solution: Tk Notepad
  45. Simple file dialog

Python Pitfalls

  1. Reuse of existing module name
  2. Use the same name more than once
  3. Compare string and number
  4. Compare different types
  5. Sort mixed data

Linters

  1. Static Code Analyzis - Linters
  2. PEP8
  3. F811 - redefinition of unused
  4. Warn when Redefining functions

Python .NET

  1. IronPython
  2. Use .NET libraries from Python
  3. Python and .NET console
  4. Python and .NET examples
  5. Exercise Python and .NET

Python and Java

  1. Jython
  2. Calling Java from Python

Jython - Python running on the JVM

  1. Jython Installation
  2. Jython Installation
  3. Jython load Java class
  4. Jython load Java class in code
  5. Jython test Java class

PIL - Pillow

  1. Install Pillow
  2. Create First Image
  3. Write Text on Image
  4. Select font for Text on Image
  5. Font directories
  6. Get size of an Image
  7. Get size of text
  8. Resize an existing Image
  9. Crop an existing Image
  10. Combine two images
  11. Rotated text
  12. Rotated text in top-right corner
  13. Embed image (put one image on another one)
  14. Draw a triangle
  15. Draw a triangle and write text in it
  16. Draw a triangle and write rotated text in it
  17. Draw a rectangular
  18. Draw a rectangle
  19. Draw circle
  20. Draw heart
  21. Rectangle with rounded corners
  22. TODO

FAQ

  1. How not to name example scirpts?
  2. Platform independent code
  3. How to profile a python code to find causes of slowness?
  4. pdb = Python Debugger
  5. Avoid Redefining functions

Appendix

  1. print_function
  2. Dividers (no break or continue)
  3. Lambdas
  4. Abstract Class
  5. Remove file
  6. Modules: more
  7. import hooks
  8. Python resources
  9. Progress bar
  10. from future
  11. Variable scope
  12. scope
  13. type
  14. Look deeper in a list
  15. Exercise: iterators - count
  16. Simple function (before generators)

Other slides

  1. Other slides
  2. Atom for Python
  3. IDLE - Integrated DeveLopment Environment
  4. sh-bang - executable on Linux/Apple
  5. Strings as Comments

marks single line comments.

  1. pydoc
  2. How can I check if a string can be converted to a number?
  3. Spyder Intro
  4. Interactive Debugging
  5. Parameter passing
  6. Command line arguments and main
  7. Infinite loop
  8. break
  9. continue
  10. While with many conditions
  11. while loop with many conditions
  12. Format with conversion (stringifiation with str or repr)
  13. Name of the current function in Python
  14. Name of the caller function in Python
  15. Stack trace in Python using inspect
  16. Module Fibonacci
  17. PyTest - assertion
  18. PyTest - failure
  19. PyTest - list
  20. SAX with coroutine
  21. Getting the class name of an object
  22. Inheritance - super
  23. Inheritance - super - other class
  24. iterator - pairwise
  25. iterator - grouped
  26. itertools - groupby
  27. Circular references
  28. Context managers: with (file) experiments
  29. itertools - izip
  30. mixing iterators
  31. mixing iterators
  32. itertools - pairwise
  33. itertools - grouped
  34. range vs xrange in Python
  35. profile (with hotshot) slow code
  36. Abstract Base Class without abc
  37. Abstract Base Class with abc Python 2 ?
  38. Abstract Base Class with metaclass
  39. Create class with metaclass
  40. Python Descriptors
  41. alter iterator
  42. Create a counter queue
  43. A Queue of tasks
  44. Filtered Fibonacci with ifilter
  45. Python from .NET

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub