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
#GALA/USDT analysis :
#GALA is currently consolidating above the support zone and the 200 EMA. A price bounce is anticipated, allowing for a continuation of its bullish momentum aimed at testing previous highs. Wait for a breakout above the $0.03736 level for a long entry.
TF : 1D
Entry : $0.03736
Target : $0.06650
SL : $0.02860
#GALA/USDT analysis :
#GALA is in an uptrend, forming higher highs and higher lows. After retracing to the 200 EMA and a support zone, the price bounced back and broke the trendline. This suggests a bullish continuation, with expectations to test previous highs.
TF : 15min
Entry : $0.05933
Target : $0.06655
SL : $0.05497
#GALA/USDT Analysis-
After forming a symmetrical triangle pattern, the price broke out, achieving a 30% gain within three days. Currently, the price has completed a retest and is approaching its previous swing high. If it successfully breaks above this level, it has the potential to rally further by over 45%.
T.F.- 1-D
ENTRY- 0.0317
SL- 0.02720
TARGET- 0.04640
Note: If the stop-loss is triggered before entry, disregard the trade as the price action may develop differently.
#GALA/USDT analysis :
#GALA is in an uptrend, making higher highs (HHs) and higher lows (HLs). The price has recently tested the support zone and is expected to bounce back from there to test the previous swing high.
TF : 1D
Entry : $0.01984
Target : $0.02441
SL : $0.01824