📜 Contributions by @karlicoss at [[python]]
📜 programming/python/python.md (contribution by @karlicoss) ☆ 📎
Table of Contents
-
[* testing](#tstng TIDDLYLINK) [[testing]]
[2020-03-27]Hypothesis has a set of Pandas strategies for generating data [[pandas]][2020-05-05]python - Run code before and after each test in py.test? - Stack Overflow[2019-08-02]python - How should I structure a pytest test only package? - Stack Overflow [[testing]] [[project]] [[pip]]- [[doctest?]]
- [[pytest can detect recursion]] [[pytest]]
- [* profiling](#prflng TIDDLYLINK) [[performance]]
-
[* packaging](#pckgng TIDDLYLINK) [[pip]]
[2020-04-02]minimal-setup-py/setup.py at master · maet3608/minimal-setup-py- [install only dependencies:
pip3 install --user -e .](#nstllnlydpndncsppnstllsr TIDDLYLINK) - [[install multiple packages at once]]
[2020-04-24]local PIP dependency: if the repo is in/path/to/repo, putHPI@git+file://DUMMY/path/to/repo@masterinsetup.py[[pip]][2019-12-15]bast/pypi-howto: How to publish Python packages on PyPI. [[pypi]]-
[2019-07-02]Testing & Packaging · Homepage of Hynek Schlawack - [[releasing on pypi]] [[pypi]]
- [* debugging](#dbggng TIDDLYLINK) [[debug]]
- [* bad things about python](#bdthngsbtpythn TIDDLYLINK)
- [* static analysers](#sttcnlysrs TIDDLYLINK)
- [* libraries](#lbrrs TIDDLYLINK)
- [* Import system](#mprtsystm TIDDLYLINK)
-
[* datetime handling](#dttmhndlng TIDDLYLINK) [[datetime]]
[2018-09-04]utcfromtimestamp – returns timestamp, unaware; fromtimestamp – returns offset + timestamp, unaware[2018-09-04]ok, seems that it’s better to usepytz.utc.localize(tz_unaware_datetime)[2020-05-02]zachwill/moment: Dealing with dates in Python shouldn’t have to suck.[2020-05-02]zachwill/moment: Dealing with dates in Python shouldn’t have to suck.
- [* logging](#lggng TIDDLYLINK) [[logging]]
-
[* docs](#dcs TIDDLYLINK)
- [[pydoc]]
- [[ipython: ? and ??]]
- [* ipdb](#pdb TIDDLYLINK) [[ipdb]]
- [[—————————————————]]
[2019-09-22]Python3 f-strings - A complete guide to the most well received feature of Python 3. /r/Python-
[2019-05-11]To yield or not to yield [[yield]] - [AST
ast.dump(ast.parse("'a' in 'aa' in 'aaa'"))](#ststdmpstprsnn TIDDLYLINK) - [[use for – else]] [[habit]]
[2018-06-18]log optimizers i used[2018-06-11]optimizing python CLI tools https://files.bemusement.org/talks/OSDC2008-FastPython/- [parser.addargument(‘rest, nargs=argparse.REMAINDER)](#prsrddrgmntrstnrgsrgprsrmndr TIDDLYLINK) [[habit]]
-
[[awesome-python https://github.com/vinta/awesome-python]]
- [[should definitely subscribe to its feed and go through again]]
- [[https://github.com/vinta/awesome-python#command-line-tools]]
- [[pretty cool https://github.com/timofurrer/try]]
- [[cool https://github.com/dbcli/mycli]]
- [hmm try that? http://docopt.org/](#hmmtrythtdcptrg TIDDLYLINK)
- [[some of these for nutrino? https://github.com/vinta/awesome-python#database]]
- [[hmm that’s interesting, visual scraping https://github.com/scrapinghub/portia]]
- [[https://www.reddit.com/r/coolgithubprojects/]]
- [[?? https://python.libhunt.com/]]
- [[do not use replace tzinfo, always localize..]] [[habit]]
[2019-01-01]multiline string – lstrip(‘\n’) for nicer formatting![2019-03-20]Tweet from Vladislav Isenbaev (@isenbaev), at Mar 20, 03:48: pickle просто скотски медленный, если что - кратно медленнее даже json’а[2019-08-11]multiprocessing vs multithreading vs asyncio in Python 3.4 - Stack Overflow [[concurrency]] [[performance]][2020-01-03]adamchainz/patchy: Patch the inner source of python functions at runtime. [[lisp]][2019-12-31]PyPy.js: Python in the web browser | Hacker News [[js]] [[webext]][2018-06-22]difflib.unified_diffis suuuuper slow…[2018-04-21]scrapy debugging [[scrapy]][2018-08-30]python’s for..else makes in ‘syntactially’ look like a total function-
[[NamedTuple]]
- [use
typing.NamedTuple](#stypngnmdtpl TIDDLYLINK) - [watch out for default add and mul, it acts as adding pairs](#wtchtfrdfltddndmltctssddngprs TIDDLYLINK)
- [you can’t easily overload init, so make types of fields robust. Use a helper method instead](#ycntslyvrldntsmktypsffldsrbstshlprmthdnstd TIDDLYLINK)
- [use
- [[Use contextmanager]]
[2018-12-08]get current function/method name- [[traitlets?]]
[2019-04-30]What’s the difference between marshmallow and sql-alchemy? /r/flask[2019-06-29]dominatepp/.travis.yml at master · karlicoss/dominatepp [[ci]][2019-08-12]usere.VERBOSEfor inline comments in regexes[2019-10-21]python - What do (lambda) function closures capture? - Stack Overflow [[plt]][2019-12-30]argparse — Parser for command-line options, arguments and sub-commands — Python 3.8.1 documentation[2020-01-07]Performance — python-rapidjson 0.4 documentation [[json]][2019-07-19]python - Argparse: Way to include default values in ‘–help’? - Stack Overflow[2019-12-31]PyPy - packages http://packages.pypy.org [[pypy]]- [Construct: kinda like struct but better? https://construct.readthedocs.io/en/latest/](#cnstrctkndlkstrctbtbttrscnstrctrdthdcsnltst TIDDLYLINK) [[parsing]]
- [[Pyrser: grammars? https://pythonhosted.org/pyrser/]] [[parsing]]
[2019-07-21]kython@git+https://github.com/karlicoss/kython.git@master dependency for setup.cfg [[pip]][2018-07-22]PyCon 2018 Talk Videos : Python https://www.reddit.com/r/Python/comments/8j4ep6/pycon_2018_talk_videos/ [[towatch]][2019-08-02]Basic usage — tox 3.13.3.dev13 documentation[2018-06-12]if there is a ‘main.py’ in script dir, it gets imported – wtf????[2019-07-20]concurrent.futures https://docs.python.org/3.7/library/concurrent.futures.html?highlight=processpoolexecutor usemap[2019-08-11]PyCQA/pyflakes: A simple program which checks Python source files for errors[2019-08-02]posargs are needed to passing adhoc args, e.g. [[tox]][2018-04-17]some misc notes- [
from http import HTTPStatus](#frmmprtstts TIDDLYLINK) [2018-01-21]use nonlocal instead of global [[habit]]- [[!r formatter]] [[habit]]
[2019-04-22]yield is often preferrable because python doesn’t have bindings in generators[2019-05-01]there is a difference between returning generator and yield from generator. the latter keeps scope, which might be useful if you have open files-
[2019-07-30]To yield or not to yield [[decorator]] - [[use putup (pyscaffold) for project generation]] [[habit]]
- [[Poetry instead of pyscaffold?]] [[python]]
-
[2019-08-25]https://docs.python.org/3.7/library/argparse.html argparse: useset_defaults - [generateordering?](#gnrtrdrng TIDDLYLINK) [[python]]
[2020-07-05]How can I color Python logging output? - Stack Overflow [[logging]] [[kython]][2020-02-16]Direct URL PEP 508 support and installing sub-dependencies from Git · Issue 5566 · pypa/pip [[pip]][2020-02-16]Allow direct urls in installrequires · Issue 6301 · pypa/pip [[python]]-
[2019-07-25]rstojnic/lazydata: Lazydata: Scalable data dependencies for Python projects - [[using pytest fixtures to inject stuff into the module]] [[python]] [[pytest]]
- [[end2end gui semi manual tests]] [[promnesia]] [[python]] [[testing]]
- [[pytest dependencies]] [[python]]
[2019-12-31]backoff · PyPI- [[Poetry for dep management]] [[python]]
[2019-12-15]Support automatic versioning setuptoolsscm-style? · Issue 140 · python-poetry/poetry- [it’s clearly not detecting changes in
install_requires; needed to reinsall](#tsclrlyntdtctngchngsnnstllrqrsnddtrnsll TIDDLYLINK) [[tox]] [2019-07-26]python - pytest exits with no error but with "collected 0 items" - Stack Overflow [[pytest]][2019-10-26]traceback — Print or retrieve a stack traceback — Python 3.8.0 documentation [[errors]]- [[separate testing and linting since mypy’s deps might be installed by accident?]] [[python]] [[tox]]
[2019-11-09]python - Run an OLS regression with Pandas Data Frame - Stack Overflow- [[figure out a better framework for python multiprocessing…]] [[python]]
[2019-09-01]vinta/awesome-python: A curated list of awesome Python frameworks, libraries, software and resources [[tui]]- [[sigh… don’t think it’s possible to properly preserve stacktraces…]] [[python]] [[errors]]
- [[strptime is incapable of handling timezones via %Z direcive??]] [[python]] [[timezone]]
[2020-03-12]encode/httpx: A next generation HTTP client for Python. 🦋[2020-09-02]Python Prompt Toolkit 3.0 — prompttoolkit 3.0.2 documentation [[tui]] [[python]][2020-09-18]testing - Python/tox Install a dependency as editable - Stack Overflow [[python]] [[tox]] [[pip]][2020-09-18]testing - Python/tox Install a dependency as editable - Stack Overflow [[hpi]][2020-09-27]python - What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, pipenv, etc? - Stack Overflow- [[adapter thigs with getattr (like in workout provider for org notes) – pretty great for adding one missing method]] [[python]]
[2019-08-25]argparseweb · PyPI[2019-09-01]vinta/awesome-python: A curated list of awesome Python frameworks, libraries, software and resources [[cli]][2019-08-02]GrahamDumpleton/wrapt: A Python module for decorators, wrappers and monkey patching.- [[attemt to figure out mixed sem/cal versioning]] [[project]] [[pip]]
- [had to remore username from hatch config? it was overriding token during the release..](#hdtrmrsrnmfrmhtchcnfgtwsvrrdngtkndrngthrls TIDDLYLINK) [[pypi]]
-
[2020-03-31]why it is hard – if you have 2fa you can’t upload packages [[pypi]] [2019-12-15]tox support python-poetry/poetry- [findpackages in setup.py?](#fndpckgsnstppy TIDDLYLINK) [[python]]
- [[eee]] [[ipython]]
[2019-09-01]KoffeinFlummi/Chronyk: A Python 3 library for parsing human-written times and dates[2019-11-17]sampleproject/setup.py at master · pypa/sampleproject- [[nicer attribute errors]] [[python]]
[2019-07-25]pytest-profiling · PyPI- [[Poetry easy pip publishing]]
- [[use quit instead of close?]] [[selenium]]
[2020-10-06]Brython [[python]] [[web]][2020-01-09]logzero: Python logging made easy — logzero 1.5.0 documentation- [[marshmallow for db handling looks interesting…]] [[python]]
- [[PandaPy]]
[2019-10-27]Ability to execute certain tests sequentially while using -n (xdist) · Issue #385 · pytest-dev/pytest-xdist[2019-10-27]pylint exceed maximum recursion depth · Issue #2388 · PyCQA/pylint[2019-10-27]Search pylint configuration in setup.cfg and pyproject.toml · Issue #617 · PyCQA/pylint[2019-11-08]How do I use regex in a SQLite query? - Stack Overflow [[sqlite]]- [[-pdbcls=IPython.terminal.debugger:TerminalPdb –pdb]] [[python]] [[ipython]] [[debug]]
- [[wonder how to make sure dataclasses are represented very effecienly?]] [[python]]
[2020-06-07]Types at the edges in Python – MeadSteve’s Dev Blog [[python]]- [[figuring out why has the package ended up in path]] [[python]]
[2020-12-08]Exhaustiveness Checking with Mypy | Haki Benita [[python]] [[mypy]]- [[hvplot: clever algebra on plots]] [[bokeh]]
[2020-04-09]naiquevin/pipdeptree: A command line utility to display dependency tree of the installed Python packages [NOT ACCEPTING PRs FOR A WHILE BECAUSE OF MAJOR REFACTORING IN ANOTHER BRANCH]-
[2020-04-23]pandas/setup.py at master · pandas-dev/pandas [[pip]] [2019-07-28]kirankoduru/scrapy-programmatically: Running scrapy spider programmatically. [[scrape]][2020-04-23]detect all subpackages properly · karlicoss/promnesia@f7451c4[2020-04-05]Configs suck? Try a real programming language | Hacker News[2020-10-14]google/python-fire: Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object. [[cli]][2020-04-23]samuelhwilliams/Eel: A little Python library for making simple Electron-like HTML/JS GUI apps [[gui]][2020-04-15]setuptools/_init_.py at master · pypa/setuptools- [[keeping testss side by side with code]] [[pytest]]
[2020-04-30]pkgutil — Package extension utility — Python 3.8.3rc1 documentation[2020-03-24]PEP 593 – Flexible function and variable annotations | Python.org[2019-08-24]Simple dependent types in Python - DEV Community 👩💻👨💻 [[mypy]] [[python]][2020-07-08]SymPy - a Python library for symbolic mathematics | Hacker News [[sympy]] [[sage]][2020-07-26]The Qt Console for Jupyter — Jupyter Qt Console 4.7.5 documentation[2020-10-15]Frame Hacks [[python]][2019-03-17]pylint useful stuff [[python]]- [[try using devpi for uploading?]] [[tox]]
[2020-05-25]docopt v argparse • Dimitri Merejkowsky [[python]][2019-12-08]Dynamically change slots in Python 3 - Stack Overflow [[python]][2020-10-24]LiveCode is a modern day HyperCard (2019) | Hacker News [[python]] [[gui]][2020-01-15]Show HN: CrossHair – SMT Assisted Testing for Python [[testing]] [[python]]-
[2019-11-10]lihaoyi/macropy: Macros in Python: quasiquotes, case classes, LINQ and more! [[macro]] [[python]] [[lisp]] [2020-01-09]What does it do? — Logbook [[python]] [[logging]][2019-11-24]How formulas work — patsy 0.5.1+dev documentation[2019-12-20]Pipenv: promises a lot, delivers very little | Chris Warrick [[pip]][2020-08-19]installrequires vs requirements files — Python Packaging User Guide [[pip]][2019-04-10]kynan/nbstripout: strip output from Jupyter and IPython notebooks [[git]] [[ipython]][2020-08-22]Plotly vs. Bokeh: Interactive Python Visualisation Pros and Cons | Paul Iacomi [[bokeh]] [[viz]]- [[hack to allow optional git dependencies]] [[pip]] [[pypi]]
[2020-03-14]jestem króliczkiem on Twitter: "or, you can encode dependencies in types: @dataclass(init=False) class FancyPath: path: Path mtime: float def _init_(self, path: Path): self.path = path self.mtime = path.stat().stmtime" / Twitter [[cachew]] [[python]][2020-04-11]Traps for the Unwary in Python’s Import System — Nick Coghlan’s Python Notes 1.0 documentation [[python]][2020-05-13]amontalenti/elements-of-python-style: Goes beyond PEP8 to discuss what makes Python code feel great. A Strunk & White for Python. [[python]][2020-05-18]The Definitive Guide to Python import Statements | Chris Yeh [[python]][2020-08-09]resize ipython notebook output window - Stack Overflow[2020-01-26]Not really. Enable something like MyPy or PyType on a big enough codebase with z… | Hacker News[2020-07-21]tmbo/questionary: Python library to build pretty command line user prompts ✨Easy to use multi-select lists, confirmations, free text prompts … [[tui]][2020-09-07]Good Integration Practices — pytest documentation[2019-07-23]Python Scatterplot Matrix | Plotly [[viz]][2019-08-18]box/flaky: Plugin for nose or pytest that automatically reruns flaky tests. [[pytest]][2019-03-05]ipython -pylab [[ipython]]-
[2018-12-23]lambdalisue/jupyter-vim-binding: Jupyter meets Vim. Vimmer will fall in love. [[vim]] [[jupyter]] [2019-05-10]Is SQLAlchemy recommended for a highly transactional, large volume database? /r/Python-
[2020-02-16]Command Line Scripts — Python Packaging Tutorial [[pip]] [2019-10-18]Hy - Wikipedia [[lisp]] [[python]][2019-12-18]Python VS Common Lisp, workflow and ecosystem - Lisp journey [[lisp]] [[python]]-
[2019-02-27]When do you us Beautiful Soup or Scrapy? : Python [[scrape]] [[python]] [2019-04-07]DataFrame — pandas 0.24.2 documentation [[pandas]][2019-04-07]Comparison with SQL — pandas 0.24.2 documentation [[pandas]][2019-02-14]There’s now a dead simple way to slap a web interface on a command line script : Python (click library) [[tui]] [[web]][2020-05-26]multiprocess.Pool + submitasync work properly with timeouts… unlike concurrent.futures? [[python]][2020-03-08]dataset: right, so synccolumn is taking quite a bit of time… I suppose because of column detection stuff [[sqlite]] [[python]]- [[gotcha with yield]] [[yield]] [[python]]
[2019-07-23]date index [[pandas]] [[python]] [[data]][2019-07-23]Which one is better: Bokeh or Plotly? - Quora [[viz]] [[python]][2019-07-23]Plotly vs Bokeh vs … : Python [[viz]] [[python]][2019-05-18]unwrap vs assert: assert is a statement, so can’t do in one line [[python]][2018-11-10]imp.loadsource for loading python module from file [[python]][2018-06-21]Ok, to prevent pollution just assert everything in _all isinstance [[python]][2018-08-26]dill seems to be superior to pickle[2019-02-12]Choosing a Python Visualization Tool - Practical Business Python [[python]] [[viz]]-
[2019-02-12]Quickstart — Bokeh 1.0.4 documentation [[viz]] [2019-02-12]python - how to set readable xticks in seaborn’s facetgrid? - Stack Overflow [[plotting]] [[seaborn]][2019-12-12]#45 Control color of each marker | seaborn – The Python Graph Gallery [[seaborn]][2020-01-17]python - Format x-axis on chart created with pandas plot method - Stack Overflow [[drill]] [[pandas]][2020-04-18]screw hatch. it’s got some weird defaults and doesn’t provide much value [[pip]][2020-02-16]python - Argparse: Way to include default values in ‘–help’? - Stack Overflow[2019-07-20]I created a GitHub repository explaining the complete process of gathering data, transforming it, getting insights and making plots using pandas, NumPy, Matplotlib and Seaborn. /r/Python [[python]] [[viz]][2020-02-18]google/pytype: A static type analyzer for Python code[2020-01-03]Comparing Python Command-Line Parsing Libraries – Argparse, Docopt, and Click | Hacker News [[python]][2020-10-24]sdispater/pendulum: Python datetimes made easy [[python]] [[datetime]][2020-09-05]fastcore: An Underrated Python Library | fastpages [[python]][2021-01-05]On Repl-Driven Programming | Hacker News [[repl]][2020-11-28]ast — Abstract Syntax Trees — Python 3.9.1rc1 documentation[2019-12-27]Why Python is my Favorite Language • Buttondown[2020-12-17]wrapt · PyPI[2020-12-13]pydot/pydot: Python interface to Graphviz’s Dot language [[viz]][2020-12-05]NBSafety Fearless interactivity for Jupyter notebooks[2020-12-29]Top 10 Python libraries of 2020 you should know about | Tryolabs Blog[2020-09-03]Overviews — PyViz 0.0.1 documentation[2020-12-05]fastai/nbdev: Create delightful python projects using Jupyter Notebooks[2020-12-07]Running Python code in a subprocess with a time limit | Simon Willison’s TILs[2020-12-07]tiangolo/typer: Typer, build great CLIs. Easy to code. Based on Python type hints.[2020-11-30]Allow to customize location of .eggs directory · Issue #1854 · pypa/setuptools[2020-10-20]PyInstrument – A statistical Python profile that focuses on the slow parts | Hacker News[2020-11-25]python - Extract traceback info from an exception object - Stack Overflow [[errors]]- [[frustrating: so much duplication]] [[pip]]
[2020-05-28]Hypermodern Python | Lobsters[2020-05-30]The Hard Part of Learning a Language • Hillel Wayne [[toblog]] [[python]]- [[I’ve gained massive amounts of random Python knowledge over the past month of actively working on my projects]] [[toblog]] [[python]]
[2020-01-04]python - How can I make setuptools install a package that’s not on PyPI? - Stack Overflow[2020-04-17]pypa/gh-action-pypi-publish: GitHub Action for publishing pre-built distribution packages to PyPI (from `dist/` dir) [[githubci]][2020-04-18]Publishing package distribution releases using GitHub Actions CI/CD workflows — Python Packaging User Guide [[githubci]][2020-12-22]uva-graphics/autoimp: Automatic Python imports[2020-01-25]My Python setup for 2020 | Noam Elfanbaum https://noamelf.com/posts/my-python-setup-for-2020/[2019-09-17]Vendoring Python dependencies with pip - Underdog.io Engineering Team - Medium https://medium.com/underdog-io-engineering/vendoring-python-dependencies-with-pip-b9eb6078b9c0 [[python]][2020-02-04]PyPy - Performance https://pypy.org/performance.html#profiler[2020-05-03]PEP 612 – Parameter Specification Variables | Python.org[2020-01-06]Please Fix Your Decorators · Homepage of Hynek Schlawack https://hynek.me/articles/decorators/[2019-09-23]bast/somepackage: Show how to structure a Python project. https://github.com/bast/somepackage[2019-11-17]holtzy/The-Python-Graph-Gallery: A website displaying hundreds of charts made with Python https://github.com/holtzy/The-Python-Graph-Gallery [[viz]][2019-12-05]Debugging Jupyter notebooks - David Hamann https://davidhamann.de/2017/04/22/debugging-jupyter-notebooks/[2019-12-13]python-poetry/poetry: Python dependency management and packaging made easy. https://github.com/python-poetry/poetry[2020-12-13]Do You Have Any Offline Programming Techniques or Tools? | Lobsters[2020-02-15]pschanely/CrossHair: A static analysis tool for Python that blurs the line between testing and type systems. https://github.com/pschanely/CrossHair[2020-04-15]egg-info in local directory makes pip think package is installed · Issue #6558 · pypa/pip[2020-04-15]I hate easy-install.pth · Issue #929 · fonttools/fonttools[2020-05-16]macropy: syntactic macros for Python | Lobsters[2020-08-22]Installation — HoloViews 1.13.3 documentation[2021-02-14]ok, naming test modules the same as originals doesn’t end up well… [[python]][2021-02-09]python - Using property() on classmethods - Stack Overflow[2021-02-10]Web Scraping 101 with Python | Hacker News- [[–system-site-packages?]] [[pipx]]
- [[strptime idea – cache time string and somehow speed up?]] [[python]]
- [[hmm, maybe possible to self-pack minimal package in setup.py? could work…]] [[python]]
[2021-02-23]Tiendil/smart-imports: smart imports for Python [[python]][2021-02-21]djrobstep/logx: best practice, zero config python logging [[python]] [[logging]][2021-02-23]textwrap — Text wrapping and filling — Python 3.8.5 documentation[2020-04-09]thebjorn/pydeps: Python Module Dependency graphs https://github.com/thebjorn/pydeps [[project]] [[python]][2020-05-15]Hello flake8 • Dimitri Merejkowsky [[pylint]][2020-07-06]Brython – A Python 3 implementation for client-side web programming | Hacker News [[python]] [[js]][2021-03-16]leeoniya/uPlot: 📈 A small, fast chart for time series, lines, areas, ohlc & bars [[python]] [[dataviz]][2021-04-02]cleanup; remove unused imports by seanbreckenridge · Pull Request 151 · karlicoss/HPI [[flake8]][2021-03-23]Iterables vs. Iterators vs. Generators » nvie.com [[python]][2021-03-07]hhatto/autopep8: A tool that automatically formats Python code to conform to the PEP 8 style guide. [[python]][2021-03-20]python - Suspend on exception in pdb - Stack Overflow [[python]] [[debug]]- [[tips about putting test next to code]] [[python]] [[toblog]]
[2021-04-04]How to make an unaware datetime timezone aware in python - Stack Overflow [[tz]][2021-04-06]python - How do I parse an ISO 8601-formatted date? - Stack Overflow[2021-03-30]setuptools - python: simple example for a python egg with a one-file source file? - Stack Overflow [[pip]][2021-04-04]Utilities — Click Documentation (7.x) [[cli]] [[python]][2021-04-16]pythonql/pythonql: A Query Language extension for Python: Query files, objects, SQL and NoSQL databases with a built-in query language [[python]][2021-05-01]PythonPackagingTerminology - Python Wiki [[pip]]
* testing [[testing]]
[2020-03-27] Hypothesis has a set of Pandas strategies for generating data [[pandas]]
https://www.hillelwayne.com/talks/beyond-unit-tests/
[2020-05-05] python - Run code before and after each test in py.test? - Stack Overflow
py.test fixtures are a technically adequate method to achieve your purpose.
You just need to define a fixture like that:
@pytest.fixture(autouse=True)
def run_around_tests():
[2019-08-02] python - How should I structure a pytest test only package? - Stack Overflow [[testing]] [[project]] [[pip]]
https://stackoverflow.com/questions/48111426/how-should-i-structure-a-pytest-test-only-package/48350323#48350323
distribute tests with package..
doctest?
pytest can detect recursion [[pytest]]
* profiling [[performance]]
[2020-03-08] what-studio/profiling: An interactive continuous Python profiler
https://github.com/what-studio/profiling
profiling live-profile webserver.py
ok, this is really nice and easy to use
[2020-07-28] kinda unmaintainerd though?
[2019-07-20] profiling with cprof
python3 -m cProfile -o stats.prof script.py
snakeviz stats.prof
[2020-01-13] rkern/lineprofiler: Line-by-line profiling for Python
https://github.com/rkern/line_profiler
[2018-03-10] profiling
python3 -m cProfile -s tottime process.py | less
sudo apt install kcachegrind
pip3 install --user pyprof2calltree
https://julien.danjou.info/guide-to-python-profiling-cprofile-concrete-case-carbonara/
python -m cProfile -o myscript.cprof myscript.py
pyprof2calltree -k -i myscript.cprof
ipython?
timeit
* packaging [[pip]]
[2020-04-02] minimal-setup-py/setup.py at master · maet3608/minimal-setup-py
https://github.com/maet3608/minimal-setup-py/blob/master/setup.py
install only dependencies: pip3 install --user -e .
install multiple packages at once
ok, apparently pip does use some sort of ‘set compiling’, so worth doing that
https://github.com/pypa/pip/issues/988
[2020-04-24] local PIP dependency: if the repo is in /path/to/repo, put HPI@git+file://DUMMY/path/to/repo@master in setup.py [[pip]]
no idea why you need DUMMY bit, must be some parsing quirk :shrug:
also, sometimes it needs //DUMMY, sometimes ///DUMMY ???
[2019-12-15] bast/pypi-howto: How to publish Python packages on PyPI. [[pypi]]
https://github.com/bast/pypi-howto
[2019-07-02] Testing & Packaging · Homepage of Hynek Schlawack
https://hynek.me/articles/testing-packaging/
Your tests do not run against the package as it will be installed by its users. They run against whatever the situation in your project directory is.
[2019-07-25] o
To achieve that, you just move your packages into a src directory and add a where argument to find_packages() in your setup.py:
setup(
[...]
packages=find_packages(where="src"),
package_dir={"": "src"},
)
releasing on pypi [[pypi]]
ok, that seems to be way easier
hatch build --clean --verbose
hatch release --strict "$@"
* debugging [[debug]]
[2019-04-09] with ipdb.launch_ipdb_on_exception() [[habit]]
[2019-12-05] python3.7 has a breakpoint() builtin + more https://hackernoon.com/python-3-7s-new-builtin-breakpoint-a-quick-tour-4f1aebc444c
ipdb pp for pretty print [[habit]]
* bad things about python
-
lambdas suck
- statements, not expressions, you are essentially restrictet to a single line
- no local variables in lambdas (although with walrus operation it’s a bit better now)
- http://math.andrej.com/2009/04/09/pythons-lambda-is-broken
- scoping (i.e. only local and global scopes)
- GIL makes the concurrency very annoying at times
- no static typing (although it’s kinda okay now with annotations and #mypy)
* static analysers
monkeytype – automatic typing annotations generation [[mypy]]
would be nice to have static analysis that checks you are not using global variables, etc.
however there are not any tools which do that…
bandit – security checks [[security]]
https://github.com/openstack/bandit
[2021-01-16] wouldn’t say it’s super useful… might detect occasional eval or whatever, but won’t help with more sophisticated stuff
* libraries
[2019-04-02] peopledoc/workalendar: Worldwide holidays and workdays computational toolkit.
https://github.com/peopledoc/workalendar
[2018-12-09] Altair: Declarative Visualization in Python — Altair 2.3.0 documentation [[viz]]
https://altair-viz.github.io/index.html
* Import system
figure it out – very confusing!
[2017-12-17] from . import module
local import
[2020-01-17] Alone Djangonaut – How python’s import machinery works
https://manikos.github.io/how-pythons-import-machinery-works
origin
[2019-06-29] python - Relative imports for the billionth time - Stack Overflow
https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time
.. are only relative in a package
However, if your module's name is __main__, it is not considered to be in a package. Its name has no dots, and therefore you cannot use from .. import statements inside it. If you try to do so, you will get the "relative-import in non-package" error.
[2019-06-11] relative imports are discouraged
* datetime handling [[datetime]]
[2018-09-04] utcfromtimestamp – returns timestamp, unaware; fromtimestamp – returns offset + timestamp, unaware
In : datetime.fromtimestamp(123)
Out: datetime.datetime(1970, 1, 1, 4, 2, 3)
In : datetime.utcfromtimestamp(123)
Out: datetime.datetime(1970, 1, 1, 0, 2, 3)
[2018-09-04] ok, seems that it’s better to use pytz.utc.localize(tz_unaware_datetime)
[2020-05-02] zachwill/moment: Dealing with dates in Python shouldn’t have to suck.
# Create a moment with words in it
moment.date("December 18, 2012")
[2020-05-02] zachwill/moment: Dealing with dates in Python shouldn’t have to suck.
# Create a moment that would normally be pretty hard to do
moment.date("2 weeks ago")
* logging [[logging]]
[2018-07-05] creating top level logger is always bad (may happen before configuring). use factory method [[logging]]
* docs
pydoc
-k: keyword search
-g: gui
ipython: ? and ??
* ipdb [[ipdb]]
related #repl
[2019-04-09] python - Use IPython magic functions in ipdb shell - Stack Overflow
https://stackoverflow.com/questions/16184487/use-ipython-magic-functions-in-ipdb-shell
shell.find_line_magic('cpaste')()
—————————————————
[2019-09-22] Python3 f-strings - A complete guide to the most well received feature of Python 3. /r/Python
That’s a part of python’s data model like `len`, `reversed`, `iter`, …:
`datetime` simply defines [`datetime.__format__`](https://docs.python.org/3/library/datetime.html#datetime.date.__format__). The method [is explained here](https://docs.python.org/3/reference/datamodel.html#object.__format__).
[2019-05-11] To yield or not to yield [[yield]]
https://barahilia.github.io/blog/computers/2017/01/04/to-yield-or-not-to-yield.html
Finally we came to this. To me it is more important that generators make code more elegant. Performance is usually relevant to smaller hot spots.
The idea is simple: in comparison to list interface where computation results are first saved and are returned only at the end, “yielding” could reach faster code and reduce memory usage. As a quick simulation we may use %timeit magic command in IPython with the following two functions:
[2019-07-30] good point about separating validation and generation
AST ast.dump(ast.parse("'a' in 'aa' in 'aaa'"))
use for – else [[habit]]
[2018-06-18] log optimizers i used
[2018-06-11] optimizing python CLI tools https://files.bemusement.org/talks/OSDC2008-FastPython/
interpreter – about 10ms
lazy imports
profile slow imports
parser.addargument(‘rest, nargs=argparse.REMAINDER) [[habit]]
process remaining arguments
awesome-python https://github.com/vinta/awesome-python
attrs – could be interesting… might solve stupid namedtuple addition etc.
https://github.com/python-attrs/attrs
This gives you the power to use actual classes with actual types in your code instead of confusing tuples or confusingly behaving namedtuples. Which in turn encourages you to write small classes that do one thing well. Never again violate the single responsibility principle just because implementing init et al is a painful drag.
should definitely subscribe to its feed and go through again
https://github.com/vinta/awesome-python#command-line-tools
pretty cool https://github.com/timofurrer/try
cool https://github.com/dbcli/mycli
hmm try that? http://docopt.org/
hmm that’s interesting, visual scraping https://github.com/scrapinghub/portia
https://www.reddit.com/r/coolgithubprojects/
?? https://python.libhunt.com/
do not use replace tzinfo, always localize.. [[habit]]
[2019-01-01] multiline string – lstrip(‘\n’) for nicer formatting!
[2019-03-20] Tweet from Vladislav Isenbaev (@isenbaev), at Mar 20, 03:48: pickle просто скотски медленный, если что - кратно медленнее даже json’а
<https://twitter.com/isenbaev/status/1108213595920166912 >
[2019-08-11] multiprocessing vs multithreading vs asyncio in Python 3.4 - Stack Overflow [[concurrency]] [[performance]]
if io_bound:
if io_very_slow:
print("Use Asyncio")
else:
print("Use Threads")
else:
print("Multi Processing")
[2020-01-03] adamchainz/patchy: Patch the inner source of python functions at runtime. [[lisp]]
https://github.com/adamchainz/patchy#patchy
Patch the inner source of python functions at runtime.
[2019-12-31] PyPy.js: Python in the web browser | Hacker News [[js]] [[webext]]
https://news.ycombinator.com/item?id=17819138
[2018-06-22] difflib.unified_diff is suuuuper slow…
[2018-04-21] scrapy debugging [[scrapy]]
scrapy shell
withsecrets scrapy shell
from scrapy.http import FormRequest
request=FormRequest(url=’http://www.quantified-mind.com/login’,formdata={‘Email’: USER,’Password’:PASSWORD,})
fetch(request) – redirects by default
sets response variable
you can do view(response) to view in browser
mind that it might be different from browsing in chrome. because of user agent?
[2018-08-30] python’s for..else makes in ‘syntactially’ look like a total function
NamedTuple
use typing.NamedTuple
watch out for default add and mul, it acts as adding pairs
you can’t easily overload init, so make types of fields robust. Use a helper method instead
def N(*args, **kwargs):
reurn NamedTuple(whatevs)
Use contextmanager
- @contextmanager; prepare; yield exactly once, then shutdown
contextlib.redirect_stdout
meh. I think it patches sys module? so it redirects sys.stdout calls only; but not all stdout
[2018-12-08] get current function/method name
def fname():
import inspect
return inspect.stack()[1][3]
traitlets?
[2019-04-30] What’s the difference between marshmallow and sql-alchemy? /r/flask
Marshmallow “converts” (deserializes) dicts to SQLAlchemy models or serializes SQLAlchemy models to dicts.
SQLAlchemy is an ORM. It maps database schema (tables) and data to Python objects.
The two packages complement each other. They cannot and do not replace each others’ functionality.
Flask-Marshmallow gives you a convenient interface to Marshmallow under Flask.
[2019-06-29] dominatepp/.travis.yml at master · karlicoss/dominatepp [[ci]]
https://github.com/karlicoss/dominatepp/blob/master/.travis.yml
hmm, minimalistic travis is not so bad..
[2019-08-12] use re.VERBOSE for inline comments in regexes
[2019-10-21] python - What do (lambda) function closures capture? - Stack Overflow [[plt]]
https://stackoverflow.com/questions/2295290/what-do-lambda-function-closures-capture
Scoping in Python is dynamic and lexical. A closure will always remember the name and scope of the variable, not the object it's pointing to.
[2019-12-30] argparse — Parser for command-line options, arguments and sub-commands — Python 3.8.1 documentation
https://docs.python.org/3/library/argparse.html >
@dataclass
(init=False)
class FancyPath:
path: Path
mtime: float
def __init__(self, path: Path):
self.path = path
self.mtime = path.stat().st_mtime
right, I suppose it’s type to use dataclasses
[2020-04-11] Traps for the Unwary in Python’s Import System — Nick Coghlan’s Python Notes 1.0 documentation [[python]]
[2020-05-13] amontalenti/elements-of-python-style: Goes beyond PEP8 to discuss what makes Python code feel great. A Strunk & White for Python. [[python]]
Use parens (...) for fluent APIs
[2020-05-18] The Definitive Guide to Python import Statements | Chris Yeh [[python]]
[2020-08-09] resize ipython notebook output window - Stack Overflow
You can toggle the scroll window in the main menu of the notebook
Cell -> Current Outputs -> Toggle Scrolling
[2020-01-26] Not really. Enable something like MyPy or PyType on a big enough codebase with z… | Hacker News
https://news.ycombinator.com/item?id=21902827
Not really. Enable something like MyPy or PyType on a big enough codebase with zero explicit annotation and it'll already find plenty of bugs and unhandled cases from the inferred types alone. Some of these are stuff a strong IDE may catch too (using the wrong function name, passing wrong number of args, etc), but some other ones are actually deeper in the code.
So already, with zero annotations, you already get value out, let alone once you type a few tricky variables that are harder for Python to track.
[2020-07-21] tmbo/questionary: Python library to build pretty command line user prompts ✨Easy to use multi-select lists, confirmations, free text prompts … [[tui]]
[2020-09-07] Good Integration Practices — pytest documentation
tests in a separate dir vs tests in a subpackage
[2019-07-23] Python Scatterplot Matrix | Plotly [[viz]]
[2019-08-18] box/flaky: Plugin for nose or pytest that automatically reruns flaky tests. [[pytest]]
[2019-03-05] ipython -pylab [[ipython]]
[2018-12-23] lambdalisue/jupyter-vim-binding: Jupyter meets Vim. Vimmer will fall in love. [[vim]] [[jupyter]]
https://github.com/lambdalisue/jupyter-vim-binding
[2019-04-13] eh, I’m using emacs now…
[2019-05-10] Is SQLAlchemy recommended for a highly transactional, large volume database? /r/Python
Yes. I've written a few systems using SQLAlchemy that see 50-100k writes and 200k or so reads per second, and as long as you're using the Core everything works fine. Also allows you to use the ORM for ease-of-development on bits that don't need performance.
SQLAlchemy is probably the one library in which I've never reached the "wait, I need to do something and can't" point. Every single weird edge case I've had to handle has been supported either natively or by being able to access the raw interfaces directly in a clean way. Fantastic library, can't recommend it more highly.
Also, the lead dev is extremely responsive on the google group and is more than happy to answer questions.
[2020-02-16] Command Line Scripts — Python Packaging Tutorial [[pip]]
✨ AI Synthesis Mistral Gemini ChatGPT Claude
Expanding this section will automatically generate an AI synthesis of the contributions in this node.