In this post I'll share all libraries, modules, snippets, boiler-plates, projects which are popular or useful in 2018 and they are related to python. The idea of the post is to make easier starting of new python project or writing a python code. This post will be frequently updated so any suggestions or corrections are welcome.
Python Boiler-plates
First of all what is a python boilerplate? In general boilerplate is that part of a form newspaper or magazine which does not change (or can be used with a small change) from edition to another. So from this perspective - python boilerplate is the code that can be used without change or with small changes. I can think for several examples like this:
- getting or setting environmental variables
- Creating generic class in OOP
- Working with dates
Python Boilerplate
Python Boilerplate - python-boilerplate.com - Python-boilerplate.com is a collection of Python boilerplates for getting started quickly and right-footed. It includes boiler-plates for:
- python version
- Python 2
- Python 3
- Tests
- unittest - unit testing framework - a Python language version of JUnit
- pytest - popular framework for small unit test and complex functional testing for applications and libraries
- tox - is a common virtualenv management and test command line tool you can run tests
- Frameworks
- Flask - a micro webdevelopment framework for Python.
- Options
- **.gitignore **
- logging
Example:
"""
You can auto-discover and run all tests with this command:
py.test
Documentation: https://docs.pytest.org/en/latest/
"""
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 4
Python snippets/templates
A piece of reusable code in programming is referred as a code snippet. It's not easy for me to tell what is the difference between snippet, template and boilerplate. I will refer to this way of distinction:
- A template/snippet offer structure/layout which to be customized
- A boilerplate provides actual code which to be used with no or few modifications
Python useful tips and tricks
Softhints - Python useful tips
This is my own project where I'm collecting different snippets, solutions and problems related to Python. All the posts are related to everyday problems and their solution. The initial idea is to create a reference project for beginners in python where they can find answers for their problems. The topics cover from basic to advanced techniques like:
- Python Configuration
- Frequently Used Python Scripts
- Python regex
- Python loop statements
- Python JSON
- Python collections
- Python lambda expressions
- Python performance and time
- Python errors
And every of this topic has subtopic. Again this post is open for suggestions and new ideas.
Example:
for i in range(0, 10):
print(i, end='')
Python-Snippets
Python-Snippets - snippets.readthedocs.io
Python-Snippets is a collection of Python snippets. It covers many different areas from basic to advanced like:
- Decorator
- Iterator And Generator
- Files
- Subprocess
- Dictionary
- List
Some of the topics are covered very well like List:
- check if a list is empty
- empty a list
- shuffle a list
- append vs extend
- split a list into evenly sized chunks
- finding the index of an item
- sort a list of dictionaries by values of the dictionary
- randomly select an item from a list
- list comprehension
Example:
from random import shuffle
# works in place
l = range(10)
shuffle(l)
100 The most useful python snippets
Python snippets of examples, to learn things and to make task easier. Some of the covered topics are:
- classtools.py assorted class utilities and tools
- formats.py various specialized string display formatting utilities.
- mydir.py a module that lists the namespaces of other module
- mymap.py different ways of implementing map
- myzip.py different ways of implementing zip
- permute.py implemented permute
Example:
def commas1(N):
"""
The more easiest way to format digits
"""
return '{:,}'.format(N)
Python-Snippets and IDEs
Many IDEs offer creation of templates, snippet and way to reuse some parts of your code. Below are listed some of the popular solutions related to IDEs like PyCharm, Atom etc: