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
🚀 Back to Back Huge Profits are made in the Premium Group
🎯🎯#ALCH/USDT has covered all the target to give a Profit of 118% to all Premium Members
👁🗨Contact @futurechief to enter the Premium Futures & SPOT Group for daily gain
🚀🚀Raining Profits in the Premium Group
🎯🎯#ALCH/USDT has covered all the targets to give an amazing profit of 29% for all Premium Members
👁🗨Contact @futurechief to enter the premium group & make daily gains on Futures as well as Spot Market
🚀🚀 31% Profit on #ALCH/USDT for our Premium Members on Binance Futures/Bybit/OKXX/Kucoin/Bitget
✅✅ All target completed
👁🗨Contact @primemod to enter the Premium Group for high quality SPOT & FUTURES Signals
☑️☑️Below you will see the Futures Premium Signals Results for (03rd February 2026)
🚀#ALCH-USDT - 118% profit
🚀#BULLA-USDT - 2363% profit
👇Trades That Incurred Loss:
❌#HYPE-USDT - 40%
✅✅Net Profit = 2441% Profit
👇🏻Signals Summary
➕Total Signals Sent out - 03
✔️Profitable Signals - 02
✖️Total Signals Lost - 01
◼️Trade cancelled without being executed - 00
✅✅Net Profit - 2441% Profit
👁🗨Contact @futurechief to enter the most profitable Futures Premium Signal Group
☑️☑️Below you will see the Futures Premium Signals Results for (15th January 2026)
🚀#ALCH-USDT - 29% profit
🚀#XMR-USDT - 142% profit
🚀#DUSK-USDT - 23% profit
👇Trades That Incurred Loss:
❌
✅✅Net Profit = 194% Profit
👇🏻Signals Summary
➕Total Signals Sent out - 03
✔️Profitable Signals - 03
✖️Total Signals Lost - 00
◼️Trade cancelled without being executed - 00
✅✅Net Profit - 194% Profit
👁🗨Contact @futurechief to enter the most profitable Futures Premium Signal Group