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
#JUV/USDT analysis :
#JUV is currently in a bearish trend, forming lower lows (LLs) and lower highs (LHs) below the 200 EMA. The price is expected to maintain its bearish trajectory and test lower levels from the current position.
TF : 1h
Entry : $1.033
Target : $0.914
SL : $1.105
#JUV/USDT analysis :
#JUV is forming a structure of higher highs (HHs) and higher lows (HLs). The price is expected to break out above the 200 EMA resistance and continue to rise. It is advisable to wait for the price to retest the support zone for a long entry opportunity.
TF : 2h
Entry : $1.640
Target : $1.780
SL : $1.550
#JUV/USDT analysis :
#JUV is presently being rejected from the resistance zone. The price is expected to retrace towards the 200 EMA and test it. This could potentially create a short trade opportunity on the lower time frame (LTF).
TF : 1H
Entry : $1.636
Target : $1.592
SL : $1.663
#JUV result
2 nd target achieved in just 1 days ✅✅✌
One more huge quick profit 21.2%🤑💰🤑
👉 Still thinking? The more you wait more you lose profit
☎️ Contact @MichaelStrategiesVip for membership and grab next breakout signal
#JUV result
1 st target achieved in just 21 house ✅✌
One more huge quick profit 10.3%🤑💰🤑
👉 Still thinking? The more you wait more you lose profit
☎️ Contact @MichaelStrategiesVip for membership and grab next breakout signal