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
#RATS is dropping in a bearish channel on 4H time frame,we are waiting for breakup from the supply zone and ceiling of the bearish channel..✨
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#RATS has falling wedge pattern on 4H Time frame,we expect it will have a good pump from the support zone in near future 💎
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#RATS has a falling wedge pattern on 4H Time frame,in the case of breakup we will see huge pump again 💎
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
#RATS bounced back from the Trendline on 2H Time frame,we expect it will pump from here until the next level 🚀
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
✨ Unlock simplicity in #BRC20 transfer!
🚀Now, easily transfer your #BRC20 assets in just ONE step!
🔄 Inscribe and transfer seamlessly for a more efficient and convenient experience.
👉https://tokenpocket.pro
Ready to experience seamless #BRC20 transactions?
Follow the tutorial:
👉https://help.tokenpocket.pro/en/wallet-faq-en/btc-wallet/brc20
#Sats#ordi#RATS#Inscriptions
【Details】https://twitter.com/TokenPocket_TP/status/1737707370523005390
【Powered By】Crypto Box
🟧 TokenPocket Now Fully supports BRC-20! #BRC20
✅#BRC20 tokens deposit, withdrawal, and token price display.
✅ Transfer your #BRC20 in one single transaction (Inscribe and Transfer in one step)
🆕We just released the iOS new version 🔺2.1.9🔺(TP Wallet) and Android new version 🔺1.9.5🔺. Upgrade your TP Wallet/TokenPocket and discover the #BRC20#Inscriptions world with us!
👉https://www.tokenpocket.pro/
#Sats#ordi#RATS#Inscriptions
【Details】https://twitter.com/TokenPocket_TP/status/1736949473048420555
【Powered By】Crypto Box