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
#PYR/USDT analysis :
#PYR is currently in an uptrend, forming a higher highs (HHs) and higher lows (HLs) structure. At present, the price is undergoing a correction phase, with expectations of a breakout from the trendline soon, which will allow it to resume its bullish momentum. Wait for a break above the $4.320 level as a signal to enter long positions.
TF : 1h
Entry : $4.320
Target : $4.845
SL : $3.969
#PYR/USDT analysis :
#PYR is in a downtrend, forming lower lows (LLs) and lower highs (LHs) structure. The price is currently trading below the 200 Exponential Moving Average (EMA). It is anticipated that the price will retrace back to the resistance zone and then reverse from there to continue its bearish momentum and test the previous swing low.
TF : 30min
Entry : $2.438
Target : $2.299
SL : $2.495
#PYR
https://www.binance.com/en/trade/PYR_BTC
Buying Zone 1850-1868
We are expecting ride in this Coin 🚀🚀🚀🚀
Buy in parts and Strictly follow as directed 👆
Sell
🤑 2000-2050
🤑 2050- 2250
🤑 2250- 2400
🚀 2400- 2600 & above
Exit/Re-Entry point- 1800
#PYR result
2 nd target achieved in just 5 days ✅✅
One more huge quick profit 22.4%🤑💰🤑
👉 Still thinking? The more you wait more you lose profit
☎️ Contact @MichaelStrategiesVip for membership and grab next breakout signal