# In Python 3.4+ you can use
# contextlib.suppress() to selectively
# ignore specific exceptions:
import contextlib
with contextlib.suppress(FileNotFoundError):
os.remove('somefile.tmp')
# This is equivalent to:
try:
os.remove('somefile.tmp')
except FileNotFoundError:
pass
# contextlib.suppress docstring:
#
# "Return a context manager that suppresses any
# of the specified exceptions if they occur in the body
# of a with statement and then resumes execution with
# the first statement following the end of
# the with statement."
# contextlib.suppress() to selectively
# ignore specific exceptions:
import contextlib
with contextlib.suppress(FileNotFoundError):
os.remove('somefile.tmp')
# This is equivalent to:
try:
os.remove('somefile.tmp')
except FileNotFoundError:
pass
# contextlib.suppress docstring:
#
# "Return a context manager that suppresses any
# of the specified exceptions if they occur in the body
# of a with statement and then resumes execution with
# the first statement following the end of
# the with statement."
What is the difference between __str__ and __repr__ in #Python?
In short, the goal of __repr__ is to be unambiguous and __str__ is to be readable.
==> "__repr__ is for developers, __str__ is for customers."
In short, the goal of __repr__ is to be unambiguous and __str__ is to be readable.
==> "__repr__ is for developers, __str__ is for customers."
๐๐ฐ Introduction to Git and GitHub for Python Developers
What is Git, what is GitHub, and what's the difference? Learn the basics of Git and GitHub from the perspective of a Pythonista in this tutorial
#python
https://realpython.com/python-git-github-intro/
What is Git, what is GitHub, and what's the difference? Learn the basics of Git and GitHub from the perspective of a Pythonista in this tutorial
#python
https://realpython.com/python-git-github-intro/
Realpython
Introduction to Git and GitHub for Python Developers โ Real Python
What is Git, what is GitHub, and what's the difference? Learn the basics of Git and GitHub from the perspective of a Pythonista in this tutorial.
๐๐บ Reading and Writing CSV Files [Video]
This short course covers how to read and write data to CSV files using Python's built in "csv" module and the "pandas" library
#python
This short course covers how to read and write data to CSV files using Python's built in "csv" module and the "pandas" library
#python
We love #Python namedtuples, a tuple subclass with named fields:
The @dataclass decorator helps reduce boilerplate code when writing your #Python classes: