Python + bash
Если вам часто требуется запускать shell команды из Python-кода, какой способ вы используете?
Самый низкоуровневый это функция os.system(), либо os.popen(). Рекомендованный способ это subprocess.call(). Но это всё еще достаточно неудобно.
Советую обратить своё внимание на очень крутую библиотеку sh.
Что она умеет?
🔸 удобный синтаксис вызова команд как функций
# os
import os
os.system("tar cvf demo.tar ~/")
# subprocess
import subprocess
subprocess.call(['tar', 'cvf', 'demo.tar', '~/'])
# sh
import sh
sh.tar('cvf', 'demo.tar', "~/")
🔸 простое создание функции-алиаса для длинной команды
fn = sh.lsof.bake('-i', '-P', '-n')
output = sh.grep(fn(), 'LISTEN')
в этом примере также задействован пайпинг
🔸 удобный вызов команд от sudo
with sh.contrib.sudo:
print(ls("/root"))
Такой запрос спросит пароль. Чтобы это работало нужно соответствующим способом настроить юзера.
А вот вариант с вводом пароля через код.
password = "secret"
sudo = sh.sudo.bake("-S", _in=password+"\n")
print(sudo.ls("/root"))
Это не все фишки. Больше интересных примеров смотрите в документации.
Специально для Windows💀 юзеров
#libs#linux
The Dead Rabbit pregnancy test injected a woman’s urine into a female rabbit. If the rabbit’s ovaries changed, she was pregnant. The rabbit was always killed to check. People wrongly thought the rabbit died only if pregnant, thus creating the euphemism "the rabbit died" to say someone was pregnant.
This outdated but effective test killed many rabbits before kinder tests were made.
🐇💉🤰
[Read more]
@googlefactss#PregnancyTest#History#AnimalTesting#OldMedicine#Science
The UK government has unveiled an unprecedented plan to gradually eliminate animal testing in medical and pharmaceutical research.
The first phase will begin at the end of 2026 and will eliminate tests on mice used to develop treatments for skin and eye irritations.
Additionally, the country has committed to reducing the use of dogs and primates in laboratories by 35% by 2030, fulfilling an election promise made by the Labour Party.
Backed by £60 million, the strategy aims to promote ethical and technologically advanced alternatives that replace animal models without compromising the safety of vaccines, medicines, or pesticides.
Although animal experiments peaked in 2015 — with over 4 million animals used — advances in alternative methods had already helped reduce that number.
However, progress has stalled in recent years, so this new initiative seeks to accelerate the full replacement of animals.
Science Secretary Patrick Vallance stated, “Nobody wants to witness animal suffering,” and the new roadmap will allow governments, companies, scientists, and animal welfare organizations to collaborate on faster and more effective solutions.
Part of the investment will go to a specialized center that will integrate technology, data, and expertise to accelerate the transition to animal-free science.
🐾 Do you think Uzbekistan should implement a similar plan to reduce and replace animal testing? 🇺🇿💭
#AnimalWelfare#AnimalFreeScience#UK#AnimalTesting#ScientificInnovation#LabAnimals#ADNMascotas#AnimalNews#AnimalProtection#OneHealth☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot
Instagram | Facebook | Twitter | Sayt | Youtube.