Wiki
  • Glossary
  • License
  • Myles' Wiki
  • Meta
  • Status
  • Android
    • Fire OS
  • Computer Science
    • Artificial Intelligence
    • Machine Learning
  • Cooking
    • Recipies
      • Desserts
        • Peanut Butter Swirl Brownies
  • Dat Protocol
  • Databases
    • MySQL
    • Postgres
  • DevOps
    • Ansible
    • Docker
  • Graphic Design
    • Adobe Illustrator
    • Design Systems
    • Pen Plotters
    • SVG
    • Zine
  • iOS
  • Linux
  • Lists
    • Books to Read :open_book:
    • Film to Watch :film_projector:
    • TV Shows to Binge :television:
    • Video Games to Play :joystick:
  • Pentesting
    • Metasploit
    • nmap Cheat Sheet
  • Productivity
  • Programming
    • CSS
    • GitHub
    • Go
    • GraphQL
    • Methodology
    • R
    • Ruby
    • Data Science
      • Organizing Data Science Projects
    • JavaScript
      • Node.js
      • Vue.js
        • Nuxt.js
    • PHP
      • Laravel
      • WordPress
    • Python
      • Anaconda
      • Celery
      • django
      • Jupyter
      • pandas
      • Useful Regular Expression
      • Wagtail
      • Web Scraping in Python
    • Static Website Generators
      • Hugo
      • Jekyll
      • VuePress
  • Raspberry Pi
  • Selfhosted
  • Setup
    • Android
    • Bag
    • iOS Applications
    • macOS Setup
    • Microsoft Windows Setup
  • Startup
  • Text Editors
    • Visual Studio Code
  • UNIX
  • User Experience (UX)
  • Windows
Powered by GitBook
On this page
  • Snippets
  • *args & **kwargs?
  • Bare asterisk (*) in function argument
  • Coerce to NamedTuple
  • Libraries
  • Data Science
  • Templates
  • Links
  1. Programming

Python

PreviousWordPressNextAnaconda

Last updated 2 years ago

Python is a programming language.

Snippets

*args & **kwargs?

>>> def hello(*args, **kwargs):
...     gretting = kwargs.pop('gretting', 'Hello')
...
...     print(f"""{gretting} {' '.join(args)}!""")
...
>>>
>>> hello("Laura", "Dang", gretting="Hi")
Hi Laura Dang!
  • by Lisa Tagliaferri, 20 November 2017.

Bare asterisk (*) in function argument

In Python 3 you can specify * in the argument list:

Parameters after "*" or "*identifier" are keyword-only parameters and may only be passed used keyword arguments.

>>> def is_birthday(*, birthday):
...     today = datetime.date.today()
...     if birthday.month == today.month and birthday.day == today.day:
...         print(f"Yes it's their birthday.")
...     else:
...         print(f"No it's not their birthday.")
...
>>>
>>> is_birthday(datetime.date(1986, 9, 19))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: is_birthday() takes exactly 1 positional argument (1 given)
>>>
>>> is_birthday(birthday=datetime.date(1986, 9, 19))
No it's not their birthday.
>>>

Coerce to NamedTuple

from typing import Any, Dict, NamedTuple, Type


class AlbumTuple(NamedTuple):
    """Album Tuple Class."""
    name: str
    artist: str
    length: float


def coerce_to_namedtuple(d: Dict[str, Any], T: Type):
    """Create a NamedTuple from a dict, ignoring extra keys in the dict"""
    return T(**{k: v for k, v in d.items() if k in T._fields})


album = dict(name="Liar", artist="Fake Shark - Real Zombie!", length=47.15)
print(coerce_to_namedtuple(d, AlbumTuple))
# output: AlbumTuple(name="Liar", artist="Fake Shark - Real Zombie!", length=47.15)

Libraries

Data Science

Templates

Links

Reference: by Eli Bendersky, 12 January 2013.

Reference: by

- PDF Table Extraction for Humans -

- Cleans companies names by stripping away terms indicating organization type -

- a file-based ORM for dataclasses -

- Databases for lazy people. -

- Lets you organize TensorFlow machine learning projects

- sampling profiler for Python programs

- Tartiflette is a GraphQL Engine, built on top of Python 3.6 and above. Focused on building GraphQL APIs using the awesome Schema Definition Language. -

- a surface language for programming Stan models using python syntax -

- Typer is library to build CLI applications that users will love using and developers will love creating. -

- Pandas and Spark DataFrame comparison for humans -

- A plugin system for loading your data and making data catalogs -

- Loading/Unloading to Amazon Redshift -

- a Python module that helps you build complex pipelines of batch jobs -

- visualize and explore big tabular data at a billion rows per second -

- cookiecutter template for the most state-of-the-art libraries and best development practices for Python.

by Artem Golubin, 29 April 2019

by Olexa Bilaniuk, 4 February 2016

by Jacob Kaplan-Moss, 21 February 2018.

by Susan Li, 17 August 2018.

, 29 April 2019

by Olga Davydova, 15 October 2018

by Florian Wilhelm, 8 November 2018.

- A collection of surprising Python snippets and lesser-known features.

by mingrammer, 20 March 2017.

How To Use *args and **kwargs in Python 3
Python 3.5 Documentation
Forced naming of parameters in Python
coerce_to_namedtuple.py
Andy Mitchhank
Camelot
:megaphone:
cleanco
Datafiles
dataset
lab_getting_started.py
py-spy
tartiflette
yaps
Typer
datacompy
intake
locopy
Luigi
Vaex
:megaphone:
Python Packages Project Generator
Detecting SQL injections in Python code using AST
Dive into Machine Learning
Einstein Summation in Numpy
My Python Development Environment
Named Entity Recognition with NLTK and SpaCy
Python at Netflix
Text Preprocessing in Python: Steps, Tools, and Examples
Working efficiently with JupyterLab Notebooks
wtfpython
Understanding the asterisk(*) of Python