What Are Python Regular Expressions Useful For? - 3 Example Scripts From Scratch

preview_player
Показать описание
In this video, we'll write 3 python scripts from scratch that show how you can do useful things with regular expressions:

1) The first example will show how regular expressions can be used to selectively update prices for certain items in a file of inventory data stored in json. The model numbers that need to be updated share a common pattern, so we can match all of them using a specific regular expression.

2) The second example will show how we can write a Python script inline inside a shell script that reads data from /proc/meminfo. The python code we write will use a regular expression to match specific lines this memory information, and then print out only those lines.

3) The third example will show how to use the 'requests' python module along with a regex to solve a very basic web scraping task that will extract titles from a web page.

SOCIALS
----------------
Рекомендации по теме
Комментарии
Автор

Not to bash on Python but #1 illustrates how bad conventional languages are in data processing. For example, same program in jq:

with_entries(select(.key | test("^[XT]R.*")).value.price += 0.17)

odnoletkov
Автор

Why is it beyond the scope of this toot to assert 'currency amounts should always be stored as integers' ?

rbettsx
visit shbcf.ru