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
🎈Hot App This Week🎈
🚀💰#Pi Network Has A New Competitor: #InterLink!⛏️⚡
[🔗InterLink Network]📌Released on Jul 15, 2025
✅Biometric face scan🤳 + liveness
✅Collections of mobile games 🎮🕹️
❌Small user base. 10 billion coin supply limit
[🔗Pi Network]📌Released on Mar 14, 2019
✅Wide global user base
✅100 billion coin supply limit
❌Many unverified users
Pick your desired bitcoin miner and start your crypto mining, earning, and trading TODAY!
Add @APKFreeDownloader_Bot to get any apk you want.
🔤🔤🔤🔤🔤🔤🔤🔤🔤
All of you already heard about Pi and its price. If you still don't have it, join Pi network and earn tokens.
Pi network - link
#Pi#Binance#Pinetwork
✨
✨#BANANAS31#PI#EVAA trades in VIP channel📈📈
We're here to help you recover your losses!
Step by step, no rush, but I will turn your losses into profit 👌🏼⚡️
😄
😄@CryptoBull_360_admin☑️
Mathematicians found that many formulas used to calculate π are connected.
About 43% of known π formulas come from one main form. Another 51% belong to related groups.
This shows many π formulas are not separate. They share common structures in math.
π is still an infinite number with no repeating digits.
📐🧠➗
[Read more]
@googlefactss
#math#pi#mathematics#science#facts