Bring Your Logic using Python
341 subscribers
109 photos
1 video
4 files
544 links
Logic building using Python : Materials, links, e-books and Code snippets
Download Telegram
#Tips Here are 2 ways to download a file in #Python:
Growth of #Python language...

Though it is a very old language, started to attract during 1999 Y2K Computer Issue.
Use faker to generate random test data:

#Python #Tips #Django
‎⁦ #python3 ⁩ regex gotcha: not every digit ("\d") looks like digits you know

‎>>> import re
‎>>> re.match(r'\d+', '٢٣٤٥٦٧٨٩')
‎<re.Match object; span=(0, 8), match='٢٣٤٥٦٧٨٩'>

‎Explanation and solution:
Here we use "yield from" to create a simple #Python generator:
As a rule of thumb, do NOT modify a collection / array / list while iterating over it.

For example, this code will NOT print all elements in the list before deleting them. #python #PythonTip
Using #Python pprint to pretty print a nested data structure:
Did you know that #Python allows you to write tests in your docstrings?
Download and extract a zipfile in #Python in just 2 lines of code
In #Python you can use a classmethod to add alternative constructors to your class:
#Python 2 more elegant string methods:
#Python #Tip

#pythontip:

In python, comparison operators can be chained:

>>> x = 3
>>> if 2 < x < 4:
... print("x is between 2 and 4")
...
x is between 2 and 4
Use tempfile.TemporaryDirectory (#Python Standard Library) to create temporary directories.

In pytest you can use its tmp_path fixture:
In #Python you can group constants using an enum:
A decorator is a function that takes another function and extends its behavior. See an example of repeat_twice decorator 👇

But what about decorators with parameters (repeat_N_times)? Then you need a function returning a function returning a function 🤩
You can use the abstractmethod decorator to force derived classes to implement certain methods: