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
🔥NEW RELEASE🔥
😁Half Guard by Nicholas Meregali😁
➡️Master the Half-Guard with 4 hours of step-by-step instruction designed to give you real control and understanding of this essential position. Learn to dominate in three key stages, Legs, Hips, and Shoulders, using each to solve specific problems and create clear, strategic progress.
➡️We start with the core concept of Camping, teaching you how to stabilize your position, manage pressure, and control posture through precise body placement over your opponent’s shields, hips, and frames, making your base extremely hard to off-balance.
$197😍$19.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NicholasMeregali#NewWave#Gi#HalfGuard
💁♀️Buy
💁♀️
🔥NEW RELEASE🔥
😁Top Half Guard By Neil Melanson😁
➡️Unlock a powerful, high-pressure top game with Top Half Guard by legendary coach Neil Melanson. As a master of catch wrestling and MMA grappling, Neil’s unique approach to half guard will completely transform the way you dominate from top position.
➡️Whether you're new to half guard or looking to refine your existing skills, this series gives you the tools to overwhelm your opponent, control the position, and finish the fight with devastating submissions
➡️Learn from one of the most innovative grappling minds in the sport and elevate your game to new heights.
$127😍$11.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#NeilMelanson#BJJFanatics#HalfGuard
💁♀️Buy
💁♀️
😁Precision Attacks and Sweeps From Butterfly Half and Knee Shield by Shawn Melanson😁
➡️Shawn Melanson returns with his fifth installment for BJJ Fanatics, and this time he’s pulling back the curtain on the sneaky, frustrating, and relentlessly effective guard system that’s been quietly dismantling opponents at every level.
➡️Melanson's method breaks away from flashy tricks and focuses on the real structure behind guard retention, off-balancing, and transitioning from defense to decisive offense
̶$̶7̶9̶😍$9.99😍
❗️Channel Info and FAQ (MUST CHECK BEFORE BUY)❗️
📱Payment: 📱📱📱
💰Submeta FOR FREE
🌈UFC Picks
👑MasterClass
✈️@bjjfanaticsinstructionals
#ShawnMelanson#HalfGuard#NoGi#Butterfly
💁♀️Buy
💁♀️