New To Python? Try THIS #python #programming #code

preview_player
Показать описание
New to Python? Try this. #python #programming #code
Рекомендации по теме
Комментарии
Автор

You can also utilise a try/except/finally block in order to do the same thing but better. This way you can both catch the error, log it or make it do whatever you want in case of an error and list under the finally block the action you want to happen regardless of the outcome.

InsaneTryps
Автор

You should always try for RAII-like behaviour, if it's a paradigm that fits in your language's syntax.

davidgillies
Автор

this is the first time python actually made sense for me. such a usefull way to handle code block that dependent to outside information than runtime.

orcofnbu
Автор

Please devs, always use context manager if a class has it. I have known about it but always ignored it because my code works well, it bit me hard.
I deployed to a droplet, monitored only to see the droplet was using 100% memory and 80%CPU after only 1 hour, my client was mad, i couldnt see which particular piece of code was causing the issue, i quickly scaled the drooplet while i investigate, the usage will go up to 95% after some time then i have to scale again.
After investigating i saw that an expection was occuring resulting in tons of file never closing causing the computer resources usage to go up to 95%, that files are read and written to 10 times a second.
Note: the file isn't the main one causing the issue, we also had playwright running which also was never closed.

daviddanielng
Автор

You run a programming channel and just learned this 😂😂😂

mattmurphy
Автор

If you just learned this then you have no business teaching python

VinceKully
Автор

Who uses this old-school approach these days?
A much more pythonic way to read/write files:

from pathlib import Path


# Bananas are berries.

neuromorphing
Автор

You finally learned about context managers?

markusklyver
welcome to shbcf.ru