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
#SCRT is rebounding from the support trendline of a falling wedge pattern, showing early signs of recovery.
The 50MA is acting as a resistance barrier above the wedge, limiting upside for now.
A strong breakout of the wedge would confirm bullish momentum and could trigger a solid rally.
#SCRT/USDT analysis :
#SCRT is currently trading within a channel. The price is likely to move upward and test the channel's resistance. It is advisable to wait for a pullback to the support zone for a long entry, as the price is expected to continue its upward movement.
TF : 4h
Entry : $0.1958
Target : $0.2354
SL : $0.1793
#SCRT/USDT analysis :
#SCRT is in a downtrend, consistently trading below the 200 EMA. The price is currently trading in a resistance zone.
It is expected to be rejected from there and will soon continue its downward movement. Wait for the breakout of the $0.1960 level for a short entry; the previous lows will be the target.
TF : 30min
Entry : $0.1960
Target : $0.1742
SL : $0.2094
#SCRT result
1st target achieved in just 1 hour✅
One more quick profit 5%💰🤑
👉 More quick profit signals available in premium channel. Hurry up 🏃♂👇
☎️ Contact @MichaelStrategiesVip