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 Sabre Grand Prix is underway in Orléans!
Strong Asian presence from:
🇯🇵 Japan, 🇰🇷 Korea, 🇭🇰 Hong Kong, 🇨🇳 China, 🇺🇿 Uzbekistan, 🇰🇿 Kazakhstan, 🇯🇴 Jordan, 🇮🇷 Iran, 🇰🇼 Kuwait, 🇲🇾 Malaysia, 🇸🇦 Saudi Arabia, 🇸🇬 Singapore, 🇹🇼 Chinese Taipei.
🔥 14 Asian athletes advance to the December 6 main draw.
Good luck to all!
📸 Photos by Eva — FIE Team
#FIE#FCA#AsianFencing
All delegations have arrived… and the real preparation begins ⚔️🔥
Athletes have started their official training sessions at the competition venue, ahead of tomorrow’s Asian Cadet & Junior Fencing Championships, featuring a large participation of Asia’s rising talents 🌏
Sharp focus, strong determination, and exciting energy ahead of the first bout 🏆
Tomorrow… it begins.
🌐www.asian-fencing.com
Follow @fencing_fca
#AsianFencing#FCA#CadetJunior#RoadToGlory
⏳ Just 1 month to go!
Asia’s future fencing stars will meet in
Jakarta, Indonesia 🇮🇩
for the Asian Cadet & Junior Fencing Championships 2026 🤺
📅 20–27 February 2026
📍 Jakarta
The countdown is on.
Are you ready? 🔥
🌐www.asian-fencing.com
Follow @fencing_fca
#AsianFencing
#FCA
#AsianCadetJunior
#Fencing2026
#Jakarta2026
🥇🏆 The Moment of Glory!
A proud scene from the podium at the Asian Cadet Fencing Championships – Kuala Lumpur 2025 🇲🇾⚔️
From Hong Kong to Kazakhstan and Uzbekistan, fencers shined with skill, passion, and true sportsmanship 💪
Congratulations to the Men’s Foil medalists on an outstanding performance and well-deserved victories! 👏
🥇 HO Shing Him Harris 🇭🇰
🥈 LAM Ho Long 🇭🇰
🥉 NURUMOV Galim 🇰🇿
🥉 MOLINA Ilyas 🇺🇿
#Fencing#AsianFencing#MensFoil#KualaLumpur#FencingAsia#Championships#FencingSpirit
🏆 Asian Senior Fencing Championship – Bali 2025 🗡️
This is where legends are forged ✨
Where pleasure 🎉, dignity 🛡️, and the spirit of competition 🔥 collide!
The thrill of victory 🥇, the clash of steel ⚔️, and the soul of competition 🏃♂️
All in one place — glory carved in blades, legends born in every touch ⚡
#Bali welcomes the elite 🤺
#AsianFencingChampionship 2025 🌏
#FCA#FencingAsia#Bali2025
#FencingPower#BladesOfGlory#Honor#AsianFencing
🔟 Only 10 Days to Go!
The countdown has begun for Asia’s ultimate fencing spectacle ⚔️🌏
Get ready as the 2025 Asian Senior Fencing Championships land on the breathtaking island of Bali! 🌺🌴
📍 Bali, Indonesia 🇮🇩
📅 June 17–23, 2025
⏳ Seven days. One stage. Endless glory.
✨ Witness:
⚡ Elite fencers from across Asia battle for supremacy
🔥 Unforgettable showdowns & rivalries reborn
🥇 New legends rising — champions forged in every bout
🎯 Precision. Passion. Power. Every point is everything.
📡 Stay tuned for:
🔴 Live updates
🎞️ Daily highlights
🎥 Behind-the-scenes action
📸 Exclusive content you won’t want to miss!
🚀 The road to greatness starts now — and it leads through Bali.
Don’t just watch history… be part of it.
🔽 Follow us & gear up for the fight of the year!
#AsianFencing#Bali2025#UnleashTheBlade
#CountdownToGlory#FencingAsia#SeniorFencing
#ChampionsRise#BladesOfAsia#FIE#TopFencers
#Indonesia#FencingElite#RoadToVictory#AFC