You should know if you use Python! 10 useful libraries

Reference site: What you need to know if you use Python! 10 useful libraries

You should know if you use Python! 10 useful libraries

There are many standard or external libraries in Python, but due to their abundance, it can be difficult to know which library to use. This time, I will introduce a Python library that is useful to know from among them.

Standard library

datetime

A module that handles dates and times. There are convenient and easy-to-use items such as date / time acquisition, character string ⇔ date conversion, and date data n days later and n days ago. For example, you can easily get the current date and time by using a datetime object that can handle dates and times together.

from datetime import datetime
now = datetime.now()
print(now)
# 2016-04-13 02:29:50.464488

shutil

A module that provides a high level of file operations. It's very easy to write operations on copying files and directories.

import shutil
shutil.copy("/src/src.txt", "/hoge/hoge.txt")

Copy the src.txt file to the hoge.txt file.

collections

There are deque (append and pop at high speed), OrderedDict (ordered dictionary), defaultdict (dictionary with default value), Counter (dictionary with counter), etc. We will be indebted to you for efficient algorithm implementation and programming contests.

from collections import Counter
count = Counter('hogehoge')
print count
# Counter({'g': 2, 'e': 2, 'h': 2, 'o': 2})

pdb

A debugger that provides features such as breakpoint setting and single-step execution at the source line level. You can also run it in an interactive shell or as a script file such as .py.

timeit

A module that measures the execution time of Python programs. You can measure the time for each code, so you can measure fine performance.

import timeit
timeit.timeit('"-".join(str(n) for n in range(100))', number=10000)

External library

tqdm

When you want to check the progress of the loop, you can easily create a progress bar like the one below.

41%||█████████            | 41/100 [00:04<00:05, 10.00it/s]

py2exe

A library that converts Python scripts to .exe for Windows. The Mac version of "py2app" and the general-purpose "PyInstaller" are also famous.

simplejson

JSON encoding / decoding library. There is "json" in the standard library, but it can be used in the same way, and it is characterized by its faster operation.

import simplejson

requests

An easy-to-use HTTP library. There is "urllib" in the standard library, but it was a little inconvenient to use. requests are very easy to use and are often recommended in recent books.

import requests
r = requests.get('URL')
print r.text

pep8

A source code check tool. Python has a style guide called PEP8, which is a common coding convention. With pep8, your code will tell you where the violation is.

Recommended Posts

You should know if you use Python! 10 useful libraries
Tips you should know when programming competitive programming with Python2 (useful library)
Useful Python built-in functions that you use occasionally
Useful to remember! 10 Python Standard Libraries
If you know Python, you can make a web application with Django
I want to know if you install Python on Mac ・ Iroha
Indispensable if you use Python! How to use Numpy to speed up operations!
What to do if you can't use scikit grid search in Python
Tips (input / output) that you should know when programming competitive programming with Python2
If you want to count words in Python, it's convenient to use Counter.
Python 3 multi-process Pool methods should use imap_unordered
Why you should use urlopen instead of urlretrieve to download Python files
Until you can use opencv with python
Python> PEP8> You should use two spaces after a sentence-ending period.> Example
Tips (data structure) that you should know when programming competitive programming with Python2
Two document generation tools that you definitely want to use if you write python
For Python 3.4 or later, you should just throw away os.path and use pathlib
If you know this much, you can write Python test code! ~ Super introductory edition ~
If you want to make a discord bot with python, let's use a framework
python> use c quick swap> #if 1 // no reshape
Until you use PhantomJS with Python on Heroku
Python if statement
How to install and use pyenv, what to do if you can't switch python versions
[Python] if statement
If you want to use Cython, also include python-dev
% And str.format () in Python. Which one do you use?
If you encounter a "Unicode Decode Error" in Python
mac OS X 10.15.x pyenv Python If you can't install
Site notes to help you use NetworkX with Python
Three Reasons Why Machine Learning Learners Should Use Python
[Python] How do you use lambda expressions? ?? [Scribbles] [Continued-1]
Python Minor Environment Retsuden-How many Python environments do you know? ~
How much do you know the basics of Python?
EP 1 Know Which Version of Python You ’re Using.
I know? Data analysis using Python or things you want to use when you want with numpy
If you don't know it, it's dangerous. Carefully explain how to use the xargs command
If you want to use field names with hyphens when updating firestore data in python
If you can't use Beautiful Soup 4 after updating to Python 3.5. ImportError: No module named bs4