Python Combat Guide
$15.00
Minimum price
$25.00
Suggested price

Python Combat Guide

A comprehensive manual about tricks, good practices and coding style for hands on Software Developer Managers and Developers

About the Book

Python Combat Guide

Is a practical guide, to setup projects from zero, or to improve existing ones.

V. 1.05 (105 - 2021-10-20) across 403 pages DIN A4, in PDF format DRM-free, provides comprehensive explanations with code samples, tips and trick, nice to do and don't-do-this.

Is a very practical guide, covering many aspects, talking superficially about many things interesting things to know like using Docker, Jenkins, Puppet, Infrastructure as code, Blue/green, canary deployment, git... and going in deep to some good practices, with a lot of source code samples.

Explain how to setup Unit Testing with pytest from the scratch, PyCharm and does some practical TDD with examples.

Make easy to use Virtual Environments and how to create your own PIP Packages.

What is it?

A very practical hands on manual for companies working with Python 3 (and moving from Python 2.7 to Python 3).

I explain my experience working in several actual projects, different sizes and teach good practices.

Like the title suggest is a Combat Guide: read it and start crushing it!.

Is the Master Class that your best friend working in a multinational will teach you to help to improve how you and your Team work.

Having in consideration Operations Engineers, SRE and SysAdmins, it explains how to move from Procedural code to OOP, and how and why to use Interfaces and Base classes (Parent) and children (subclasses).

I use practical examples, and compare Bash and Python for different scenarios, and I show pytest Unit Testing from the scratch.

Probably you'll love it if you know Java or PHP cause in 5 hours will enable you to write code in Python.

I also provide a very simple Flask Web Application, so you see how easy it is, a mini OOP application working against MySQL in Docker, a simple SQLITE3 example, a simple GUI TKinter LDAP application, Cron Jobs that send email, Sorting Data Structures using .sort(), sorted() and lambdas, Docker samples...

When possible instructions are provided for Ubuntu Linux, Mac Os X and Windows.

Price

Price is $25 suggested with a minimum of $15.

I decided to set the price to the minimum ($5) during covid, in order to help people that want to learn and improve. (this is not a manual for novices, but for people that actually know Python, SysAdmins, Architects and Managers).

As the worst has passed and the book is addressed to Senior staff, I decided to raise it a bit, as it contains a lot of value and I have committed many hours for it.

You may still benefit from offers handled from LeanPub, and bundles.

Special Covid-19

I release this guide during coronavirus quarantine, in Ireland.

This is a technical guide, intended to serve to all level of Medium-Senior Developers and to SDMs (SDM - Software Development Managers).

Also useful for Team Leads and Project Managers..

It is not a basic manual, however I want to give a chance to non-tech people to learn how to program in Python, so they can get a good life or in the case of the scientists and academics that lost their jobs in the universities and need to go back to the market. Many of them use tools like Jupyter Notebook with Python, so they only need a Master Class and examples to empower them to work in modern projects, with Git, Unit Testing, nice good practices, Team work...

What is not?

A typical manual to learn Python for beginners.

If you're looking for this, this is not your book.

Is focused on writing CLI programs, Crons, Unit Testing and shows some Flask but does not cover Django.

It is not a manual to learn specific Python language features in deep. Does not cover Python 3.7, 3.8, 3.9 or 3.10 new features as the code I write tries to work across many different versions of Python (and Servers running them).

Neither explain Architecture Patterns like Event Queues or Microservices. Or how to write API's, there are many books for that.

It just go for pointing the effective way to build CMD Line applications, Crons, use Dependency Injection, and Unit Testing in a very professional way.

Also cover certain common sense aspects for working in Team, good practices, and some Scaling tricks.

So basically allowing SRE, DevOps and Managers to improve the way they run Command Line Appications, Server side scripting, Server Monitoring...

Currently I don't cover Google Cloud Python Engine or Amazon AWS lambda with Python, although I have plans to do it.

I think you will learn many useful things, but if you buy it and you are not satisfied, please feel free to return it. When you buy it you have a period of time to return it, which at the moment of this writing is 45 days. I only had one return, and it was a professional editorial that wanted to sell the book in the States and world wide. But honestly, I like to keep all the rights and to be able to communicate with you and to update the book often. ;)

Is the code in gitlab?

Yes, most of the code is in gitlab, so you can download and just run it.

However is better to follow the book, as there are some errors intended, in order to show what not to do, and without reading the book you'll not understand it.

Even if you didn't buy the book, feel free to download the source code in gitlab:

https://gitlab.com/carles.mateo/python_combat_guide

The Python with MySQL in Docker sample application can be downloaded from here:

https://gitlab.com/carles.mateo/python-mysql-example

About the Author

Carles Mateo
Carles Mateo

I’m Carles Mateo, since January 2020 working as Operations Engineer for Blizzard Entertainment in Cork, Ireland.

Previously worked as Cloud Architect and SDM for Sanmina, in Ireland and United States, where I created and I did lead a Python and C project for a Storage Manager for our 4U Cold Storage Servers 1PB and 2U SSD and 1U NVMe with NICs up to 2x100Gbps, which will restore redundancy in the RAID when a drive dies, very quickly, using ZFS and DRAID.

I helped several multinationals:

  • Volkswagen IT (gedas) where I got promoted to head of department of Reusability and Code Components and previously I lead the SEAT's Intranet project, I solved TCP/Ip transmission problems in project PortIc for Barcelona's port (EDI Transfer), I created a project to transfer warranty documents over Web and TCP/IP instead of X.25 expensive lines, and worked for CaixaBank (formerly "la caixa") creating a Documentum solution programing the GUI and DLL's.
  • Winterthur Insurance (Axa) where I lead the project to deploy a new Contact Center Software, the e-Commerce web platform and the insurance of health policies (special Data treatment)
  • BBVA Tickets where I was responsible of the platform (Sun Solaris and Oracle)

and several CSP and ISP, Start ups, e-Commerces, Online travel agencies, eCommerce…. as CTO or in hands on positions leading teams and coding myself, in Software Development, SRE and Operation roles.

I was one of the 5 Senior BackEnds that wrote Privalia's new website, from the scratch, with inheritance, and lead a KPI Dashboards for CEO, really learning the internals of all the areas of the company through the data.

The last company I was CTO for, in Barcelona, was sold to airbnb for 45 million euros.

My friends say that everything I touch turns into gold, and my very good friend Jaume (R.I.P.) used to say that I was the most brutal technical guy, solving all the difficult technical issues easily, that he ever met. I've very grateful thoughts and memories for all the people that did speak up how well they considered me, and that were fair Other people tried to take advantage byo never telling me how good and helpful I was so they could pay me less. What they didn't know is that I always had offers paying me double, and I was choosing to help them.

Now I only accept fair agreements. I know my value.

I started programming when I was 5 years old, at 10 I won a contest at Spanish State level, getting a Pc with a green phosphorescent monitor and a floppy drive, and I've lived the times of the BBS, much before Internet.

I've coded many Freeware Software, and Open Source Software, and I created the first system in Europe to sell Tickets for musical events, in 1995, for Tick Tack Ticket. I created this e-Commerce engine, with render template system completely in C, cgi-bin, HTML.

I love Software and Hardware.

I've worked with C, Java, PHP, Python... and my knowledge of PHP Unit Testing really reached its best when I was working for a bank.

I've invented the CSort algorithm.

In my free time I teach some students to get pro in coding. Most of my time now I work with Python 3, Docker Containers and Linux.

You can find information about me in my blog.

https://blog.carlesmateo.com/bio

Bundles that include this book

$40.00
Suggested Price
$17.00
Bundle Price
$40.00
Suggested Price
$20.00
Bundle Price
$80.00
Suggested Price
$35.00
Bundle Price

Table of Contents

  • Index per version 1.03 published on 2021-09-24
  • Dedication.............................................................................................................................. 2
  • Thanks................................................................................................................................... 2
  • Contact me............................................................................................................................. 4
  • Receiving Free Updates......................................................................................................... 4
  • If you’re not satisfied............................................................................................................... 4
  • About this Combat guide......................................................................................................13
  • About the author................................................................................................................... 13
  • Disclaimer............................................................................................................................. 13
  • About coronavirus................................................................................................................. 14
  • For the very beginners.......................................................................................................... 14
  • Hacker Rank.................................................................................................................... 16
  • About Floating point / decimals and Locale (international users).....................................17
  • Floats in Python........................................................................................................... 17
  • Decimals in programs..................................................................................................18
  • Why Python versus Bash (reasons for SRE)........................................................................20
  • OOP vs Procedural code (SRE)...........................................................................................20
  • A practical sample of OOP for the SRE world: SSH Server Automation......................22
  • SSH Server improved with Paramiko SSH Libraries....................................................26
  • SSH to a Server with Paramiko SSH Libraries and Username and Password and
  • execute a Command...................................................................................................27
  • OOP small explanations recap....................................................................................30
  • Why not Python 2.7?............................................................................................................ 31
  • Few differences between Python 2 and 3........................................................................31
  • print()............................................................................................................................... 32
  • Use a printing method instead of calling directly print()....................................................33
  • Use of raw_input in classes.............................................................................................33
  • Floats............................................................................................................................... 33
  • Floats in Databases and Currencies................................................................................34
  • Things I don’t like from Python.............................................................................................38
  • Thigs I like from Python........................................................................................................38
  • Tools.................................................................................................................................... 40
  • IDE: PyCharm Professional.............................................................................................40
  • CVS: GIT......................................................................................................................... 40
  • Unit Testing: PyTest.........................................................................................................41
  • Google Docs and google drive.........................................................................................41
  • Directories used................................................................................................................... 41
  • File names............................................................................................................................ 42
  • File names for Classes....................................................................................................42
  • Classes inside files, one file per class..............................................................................42
  • File extensions................................................................................................................. 43
  • File paths......................................................................................................................... 45
  • Working with GIT.................................................................................................................. 46
  • Gitlab............................................................................................................................... 46
  • Commit messages........................................................................................................... 46
  • Commit messages for Gitlab.......................................................................................47
  • Branches.......................................................................................................................... 52
  • Branching Strategy......................................................................................................53
  • Git flow........................................................................................................................ 54
  • GitHub flow.................................................................................................................. 56
  • Production branch with GitLab flow.............................................................................57
  • Environment branches with GitLab flow......................................................................58
  • Release branches with GitLab flow.............................................................................59
  • Merge/Pull requests....................................................................................................60
  • Feature branches........................................................................................................ 61
  • Closing or Linking issues using comments in GitLab...................................................61
  • Removing feature branches after merge.....................................................................62
  • Have always backups from Master..............................................................................62
  • Git rebase.................................................................................................................... 62
  • Git submodules................................................................................................................ 63
  • Fetch................................................................................................................................ 65
  • Pull from the repo............................................................................................................. 65
  • Pushing to the repo.......................................................................................................... 65
  • Keep an eye to new changes in commits through the Log section...................................66
  • Never ever submit to the repo local changes you want to test.........................................66
  • Never commit Debug Lines..............................................................................................67
  • Solving when one of your colleagues has submitted a file from .idea folder.....................67
  • Development Environment...................................................................................................69
  • Use Linux......................................................................................................................... 69
  • I recommend you to use PyCharm...................................................................................69
  • Use a Virtual Environment for your projects.....................................................................69
  • Coding.................................................................................................................................. 70
  • General Style................................................................................................................... 70
  • Structure...................................................................................................................... 70
  • Comments................................................................................................................... 71
  • Use @TODO............................................................................................................... 71
  • PEP-8.......................................................................................................................... 71
  • MT Notation................................................................................................................. 72
  • Short Code in Methods is preferred.............................................................................74
  • About ' or " (apostrophe or double quote)........................................................................74
  • Return.............................................................................................................................. 75
  • Error code in return.......................................................................................................... 76
  • Predictability in return: Return always the same..............................................................76
  • Files................................................................................................................................. 76
  • Operators......................................................................................................................... 77
  • Tabs or spaces................................................................................................................ 77
  • Space to breath................................................................................................................ 78
  • Too much compressed code............................................................................................78
  • Use parentheses, Luke....................................................................................................80
  • Use Parenthesis on if evaluation as much as possible................................................81
  • Short-circuiting behavior in Chained Comparison........................................................82
  • Avoid using short-circuiting with methods....................................................................82
  • Variables and Names.......................................................................................................85
  • Do not use Global variables.............................................................................................87
  • Class variables are Static or not, depending on the context.............................................87
  • Declare variables on top of the Class and Method...........................................................90
  • Declaring variables on top in Methods and Functions.................................................90
  • Declaring variables on top in Classes..........................................................................91
  • Do not modify arrays and variables passed by reference (unless you want to do that)....94
  • How variables are passed to a method/function?.............................................................95
  • String, our immutable friend........................................................................................95
  • Mutable and Immutable variables....................................................................................96
  • Class Names................................................................................................................... 97
  • Class Constants............................................................................................................... 97
  • Comparing with constants................................................................................................98
  • Properties........................................................................................................................ 98
  • Properties and variables defined on top of the Method....................................................98
  • Functions and Methods....................................................................................................99
  • Do not print inside classes, use the capacity of Python to return more than a parameter
  • instead......................................................................................................................... 99
  • Warning: Do not repeat Method of Function names..................................................100
  • Function/Method Parameters with a default value (Keywords)..................................100
  • Keyword Argument for a Method/Function................................................................101
  • Type Hinting and Annotations...................................................................................104
  • Lists, Arrays, Dicts, Tuple..............................................................................................106
  • Mixed power of Lists, Dicts........................................................................................106
  • Dynamic grow............................................................................................................ 107
  • “in” very important check to do..................................................................................107
  • Convenience of having a method for checking “in”....................................................108
  • Default dict, to save memory.....................................................................................109
  • Sort a List by key, example.......................................................................................110
  • Arrays and index -1........................................................................................................110
  • Expect the unexpected (Corner cases)..........................................................................111
  • The Happy Path........................................................................................................ 111
  • Use getters and setters..................................................................................................112
  • Use update_ for methods that update Objects, not get_................................................113
  • Jumps of line \n to the end.............................................................................................114
  • If / else........................................................................................................................... 115
  • Else in loops.............................................................................................................. 116
  • Careful String evaluations.........................................................................................116
  • Calling variables by name in Methods or Functions.......................................................117
  • If for text properties........................................................................................................117
  • Avoid repeating code.....................................................................................................118
  • Comments..................................................................................................................... 119
  • Python doc..................................................................................................................... 119
  • Document...................................................................................................................... 119
  • No dead code................................................................................................................. 120
  • We avoid Magic Methods...............................................................................................120
  • The power of range........................................................................................................121
  • Avoid using yield, avoid using lambdas..........................................................................124
  • Avoid using list comprehensions....................................................................................125
  • Avoid using Regular Expressions, unless you know what you are doing.......................125
  • Creating Web Applications / Web Services with Flask...................................................126
  • Hello World Application.............................................................................................126
  • Another simple Web Flask Application......................................................................129
  • A more cool Flask Application...................................................................................130
  • For using in Production..............................................................................................136
  • Files for holding Data Structures and Databases...........................................................137
  • Collation.................................................................................................................... 137
  • Data types in the Database.......................................................................................137
  • Data serialization........................................................................................................... 138
  • Some tricks to Scale Production....................................................................................141
  • A real case of Serialization in the world of the videogames.......................................141
  • Adding compression..................................................................................................141
  • Database Sharding....................................................................................................142
  • Advice: Do not allow Marketing to query Production Servers....................................144
  • Use of the Slaves for reading....................................................................................144
  • Load Balancing..........................................................................................................144
  • Redis cache............................................................................................................... 144
  • Cache on local webservers.......................................................................................144
  • NGINX, CDNs........................................................................................................... 145
  • Python Virtual Environments..........................................................................................145
  • Creating a Virtual Environment in Python 3...............................................................146
  • Creating a Virtual Environment in Python 2...............................................................148
  • Activating the Virtual Environment.............................................................................148
  • Deactivating the Virtual Environment.........................................................................148
  • Knowing what Python Packages are installed................................................................149
  • requirements.txt file........................................................................................................150
  • Python Threads.............................................................................................................. 151
  • Using threading......................................................................................................... 151
  • Using multiprocesses................................................................................................153
  • Prefixes: MT Notation....................................................................................................157
  • Expect the Unexpected..................................................................................................159
  • Corner cases and assumptions......................................................................................161
  • Do no escape to shell to run a program, if you can do it from Python............................161
  • Escaping to shell, when really needed...........................................................................162
  • An example of things that could be wrong.................................................................162
  • Try to have Common Libraries for the Common Tasks..................................................166
  • OOP................................................................................................................................... 167
  • Initialising the variables in the Constructor.....................................................................170
  • Use init_variables()........................................................................................................ 171
  • Bug fixing............................................................................................................................ 174
  • Focus, make sure you don’t do mistakes.......................................................................174
  • Better Quality than Quantity...........................................................................................174
  • Cross Testing................................................................................................................. 174
  • Check the Logs.............................................................................................................. 175
  • Methodology....................................................................................................................... 178
  • Methodology serves a purpose......................................................................................178
  • We are modern heroes..............................................................................................178
  • Deploying to Production.................................................................................................178
  • Create a Deploy or Launch or Change Request Document in the issue tracker........178
  • Deploying to Production using immutable Docker Containers and/or Microservices. 179
  • Requirements.txt.......................................................................................................181
  • In Dockerfile do not use FROM latest........................................................................183
  • Running in Production....................................................................................................183
  • Check for Log Errors regularly in Production Servers................................................183
  • Profiling.......................................................................................................................... 183
  • Forensics / Postmortem analysis...................................................................................183
  • Do not use Database Stored Procedures.......................................................................183
  • Webservices and API are good, microservices are not always the wisest choice..........184
  • Blue green Deployment vs Canary, and Rolling Upgrade..............................................185
  • Automated Code Testing Quick Overview..........................................................................187
  • Unit Testing Framework.................................................................................................187
  • py.test versus unittest?..............................................................................................187
  • Tests are not optional....................................................................................................187
  • Run the Unit Tests......................................................................................................... 188
  • Run tests frequently..................................................................................................188
  • Do not reuse other Tests...........................................................................................188
  • Importance of running good Tests (Unit Testing Tests)..................................................188
  • Problems from Bash invoking parameters with quotes or without..............................189
  • Emails in the Tests.........................................................................................................190
  • Testing Infrastructure as Code...........................................................................................191
  • Managing the Team............................................................................................................ 192
  • Managing takes time......................................................................................................192
  • Synchronizing the knowledge of the Team.....................................................................192
  • Demos and Share the Pain............................................................................................192
  • Be always fair................................................................................................................. 193
  • Allow to learn and creativity...........................................................................................194
  • New members join the Team.........................................................................................195
  • Kick Off Meeting........................................................................................................195
  • Concentrated advice for my Team.................................................................................195
  • Methodology for the Development, Presentations, Documents and Demos.......................196
  • Prepare Demos: name Objects and Variables...............................................................196
  • Prepare Demos: prepare it in advance and test that everything works...........................196
  • Take care of the details..................................................................................................196
  • We don’t avoid confronting problems.............................................................................197
  • We document and write Functional Analysis..................................................................197
  • Checking the Functional Analysis before starting programming.....................................198
  • We reply the emails.......................................................................................................198
  • We do Stand up Meetings..............................................................................................198
  • Exercises for Candidates / New Recruitments....................................................................198
  • Tools to discuss remotely (screener).............................................................................199
  • First, the FooBar exercise..............................................................................................199
  • Second, Power of 2 exercise.........................................................................................199
  • What we take in consideration from the candidate?.......................................................199
  • Being nice...................................................................................................................... 200
  • Fair Questions for Developers.......................................................................................200
  • Working with pytest Unit Testing........................................................................................201
  • Installing py.test in Ubuntu.............................................................................................201
  • Installing py.test for Python2.....................................................................................201
  • Installing py.test for Python3.....................................................................................202
  • Running the Tests in a Virtual Machine like VirtualBox..................................................202
  • Running the Tests in a Docker container.......................................................................202
  • Location of the code samples and tests.........................................................................203
  • Writing the first test........................................................................................................ 203
  • Using classes for testing................................................................................................204
  • Do not use Constructor __init__ in your pytest classes.............................................205
  • Testing a real class...................................................................................................206
  • Extending our first test...............................................................................................207
  • Extending a bit more and getting errors.....................................................................209
  • Fixing our Test using TDD.............................................................................................211
  • Advantages and disadvantages of having everything in one single method...................213
  • Reusability..................................................................................................................... 216
  • Adding improvements discussed....................................................................................216
  • Skipping a Test.............................................................................................................. 218
  • Skipping a Test based on version of the library.........................................................218
  • Skipping a Test based on Python version..................................................................219
  • Creating unit testing for DiskUtils...................................................................................220
  • Do not reuse variables in Unit Testing Code..................................................................222
  • Adding pytest to PyCharm Community Edition...............................................................222
  • Code Coverage.............................................................................................................. 225
  • Adding Dependency Injection........................................................................................229
  • Stubs and Mocks and Monkeypatching..........................................................................233
  • Putting all together......................................................................................................... 238
  • Exercises................................................................................................................... 246
  • Refactors....................................................................................................................... 246
  • How to do a Refactor of legacy code.........................................................................247
  • Fixtures.......................................................................................................................... 248
  • Fixture to patch time.sleep........................................................................................248
  • Pytest config file conftest.py...........................................................................................251
  • Testing Exceptions.........................................................................................................253
  • Catching an expected Exception...............................................................................253
  • Code Coverage on Exceptions..................................................................................253
  • Test Helper for OS calls testing.................................................................................254
  • Testing STDOUT, print, and Fixture capsys...................................................................260
  • A Refactor from CSV reader spaghetti code to OOP with Unit Testing..........................261
  • CSV format................................................................................................................ 261
  • CSV reader code (spaghetti code)............................................................................262
  • Problems with this code spaghetti-code2.py..............................................................262
  • Addressing some errors more. spaghetti_code3.py...................................................265
  • Do not use dash in file names...................................................................................265
  • Use if __name__ == "__main__":..............................................................................265
  • Magic Attributes.........................................................................................................266
  • Extracting the functionality. spaghetti_code4.py........................................................267
  • Unit Testing for spaghetti_code4.py test_spaghetti_code4.py...................................269
  • Converting spaghetti_code4.py to OOP code............................................................272
  • The Unit Testing for the OOP code...........................................................................274
  • Converting a simple script to list drive to a well tested program with Unit Testing.....278
  • When to use Data Objects and when to use just Arrays or Dictionaries?..................317
  • Testing your code as Superuser and regular user.........................................................318
  • Running your Docker Container as non-root, regular user.............................................319
  • Test as root and non-root..........................................................................................319
  • Running Tests in actual Hardware?...........................................................................319
  • Tricks and Appendix........................................................................................................... 320
  • A mix: Unit Testing on actual Hardware.........................................................................320
  • Creating PIP Packages..................................................................................................321
  • Convert a Python program to a Cron.............................................................................327
  • Using Crontab........................................................................................................... 331
  • Using Python Scheduler Class and Docker...............................................................332
  • Catching CTRL + C inside your Python programs.....................................................334
  • Class FileUtils................................................................................................................ 335
  • Class SmtpUtils.............................................................................................................. 341
  • Exercises................................................................................................................... 344
  • Different ways of doing things........................................................................................344
  • Exercises................................................................................................................... 347
  • Printing in color to the Linux Terminal............................................................................348
  • Working with SQLITE3...................................................................................................354
  • Thinking about the decision of designing Interfaces and Base Classes extended..........360
  • The boring theory......................................................................................................360
  • Practical approach.....................................................................................................361
  • Practical approach for SRE.......................................................................................368
  • Handling parameters from Command Line.....................................................................369
  • ....................................................................................................................................... 371
  • Printing to STDERR.......................................................................................................372
  • LDAPGUI a tkinter GUI program to query LDAP............................................................373
  • CTOP.py A CLI program that includes all these lessons................................................380
  • cmemgzip.py A CLI program that includes all these lessons..........................................381
  • How to add your library as a package in PIP..................................................................382
  • PEP8 Style Validator......................................................................................................387
  • Sorting Arrays and Data Structures and Lambdas.........................................................388
  • Crashing Lambdas....................................................................................................389
  • Sorting an Array of Objects with Sorted.....................................................................390
  • Trade off Memory versus Time..................................................................................392
  • Sorting a very simple array with .sort()......................................................................392
  • package: First with lambda........................................................................................393
  • A lambda for separating evens and odds..................................................................393
  • Merging two dictionaries................................................................................................394
  • Merge two dictionaries using .update()......................................................................394
  • Dict unpack inside another Dictionary.......................................................................394
  • Merge into a new Dictionary using dict and kwargs...................................................395
  • Generating a new Dictionary, merge of other two, using Collections.........................395
  • Merging with itertools.................................................................................................396
  • Merging with Python 3.9 only....................................................................................396
  • Making a copy of a Dictionary...................................................................................396
  • Help in python interpreter...............................................................................................397
  • Working with Python and MySQL from a Docker Container, an example project...........398
  • Installing the MySql driver.........................................................................................398
  • Dockerfile.................................................................................................................. 399
  • build_docker.sh......................................................................................................... 400
  • docker_run.sh............................................................................................................ 401
  • docker_run_mysql.sh................................................................................................401
  • start.sql...................................................................................................................... 402
  • select_values_example.py........................................................................................403
  • Executing the Container............................................................................................404
  • Entering the Container and running the code............................................................405
  • Tying together MySql and a Python Menu with Object Oriented Programming..............406
  • MySQL Library.......................................................................................................... 406
  • A Data Object: CarDO...............................................................................................408
  • Queue Manager........................................................................................................ 410
  • Useful libraries.................................................................................................................... 415
  • Bibliography........................................................................................................................ 418

The Leanpub 45-day 100% Happiness Guarantee

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

See full terms

Do Well. Do Good.

Authors have earned$10,909,613writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.

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), EPUB (for phones and tablets) and MOBI (for 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, EPUB and/or MOBI files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub