Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active September 3, 2022 22:05
Show Gist options
  • Select an option

  • Save wilmoore/93905ff4eccc8df52c61192bbfa3f027 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/93905ff4eccc8df52c61192bbfa3f027 to your computer and use it in GitHub Desktop.
Learn Python The Polyglot Way

Learn Python The Polyglot Way

Made with ♥ by Polyglot.

Why buy this guide? Well, if you were already thinking about learning how to code at all or wanted to specifically learn python, then, this is the guide for you because ...


Guide to programming Python by referencing other programming langauges. A polyglot Software Engineer has a broad set of skills, one of those skills is being able to understand, build with, and debug within many diverse programming languages.

Learn Python The Polyglot Way teaches you by allowing you to make the right mistakes on your own, not the ones we can help you avoid. By helping you avoid common issues, you learn more because the same lessons can be applied for any programming language you choose. You could almost take this guide, swap out Python and any pythonisms and it could be used as the base for a book for another programming language beause learning most programming lanuages is essentially the same.

Directory Structure

Given you are not new to software programming languages, you've probably noticed that understanding a directory structure makes working with the code a lot smoother. There are no perfect solutions here, only well-reasoned community recommendations; however, that will do since the community usually speaks loudest through experience and through toughing it out through difficult situations where lessons are learned and those lessons are packaged up into standards or best practices or community recommendations.

Advanced

todos

  • call out paths and / vs c:\ on windows and keeping things cross platform
  • understand how the language handles finding packages and modules

Modules & Module Attributes

what system file path was the module imported from?

mod.__file__

Helpful Snippets

>>> sys.path.append(r'/Users/...')

Terminology

module

a file containing python code and named with extension ending in .py.

package

a directory of python modules & includes a __init__.py file.

distribution

The package directory archived as *.tar.gz or .zip.

Dependency Managment

Project Scaffolding

Package Publishing

Virtual ENV Management

poetry.lock

Development ENV for teams can test with & without. Library, no checkin

Main

Every modern programming environment has a way to set a function or a module as the main or default piece of code to run upon initial execution. Python provides facilities that make it easy to figure out if a module is being called as the main entrypoint or if it's simply being imported.

We would test this by modifying sys.argv[0] before calling the print function below.

if __name__ == `__main__`
  import sys
  print('Hello {0}'.format(sys.argv[0]))

Tutorials

Courses

Python Source Code Examples

Crypto

Useful Python Packages

Package Manager
Python Version Manager
Date & Time
Record Linkage
Others
numpy
pandas
PySpark
cx_Oracle
snowflake.connector
pyodbc
fastjsonschema

Poetry

Poetry installs your packages into the virtual environment's site packages. This allows pytest to find your package without the need to manipulate sys.path directly in the test's __ini__.py.

Command Reference

This list is not exhaustive. These are all of the commands I've actually had to use so far.

dev
> poetry new example
> poetry install
> poetry run pytest
release
> poetry build
> poetry publish
dependencies
> poetry add requests
> poetry add pylint flask
> poetry install
python version
> poetry env use python3.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment