Explain Codes LogoExplain Codes Logo

Python

What can I do about "ImportError: Cannot import name X" or "AttributeError: ... (most likely due to a circular import)"?

python
circular-dependencies
import-best-practices
module-design

How do I read from stdin?

python
input
stdin
io

How do I concatenate two lists in Python?

python
functions
collections
best-practices

How do I merge two dictionaries in a single expression in Python?

python
dataframe
pandas
best-practices

Running shell command and capturing the output

python
subprocess
shell-execution
error-management

How do I correctly clean up a Python object?

python
contextlib
resource-management
best-practices

Does Python have a string 'contains' substring method?

python
functions
performance
best-practices

Finding and replacing elements in a list

python
list-comprehension
functional-programming
data-structures

Check if something is (not) in a list in Python

python
performance
best-practices
dataframe

Catch multiple exceptions in one line (except block)

python
exception-handling
best-practices
error-handling

How can I force division to be floating point? Division keeps rounding down to 0?

python
division
floating-point
integer-division

What's the pythonic way to use getters and setters?

python
best-practices
properties
pythonic-way

Printing Lists as Tabular Data

python
dataframe
pandas
pretty-printing

When to use cla(), clf() or close() for clearing a plot

python
plotting
memory-management
interactive-plotting

How to concatenate (join) items in a list to a single string

python
string-concatenation
list-manipulation
python-stdlib

Convert JSON string to dict using Python

python
json-loads
json-dumps
error-handling

Traverse a list in reverse order in Python

python
iterators
performance
best-practices

How to get current CPU and RAM usage in Python?

python
performance
multiprocessing
memory-usage

How to convert webpage into PDF by using Python

python
pdfkit
weasyprint
pypdf2

List of unique dictionaries

python
data-integrity
list-comprehension
numpy