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
#Back Stronger And Better.🦾
Getting Back On Track After An Unsuccessful Losing Streak
Did you lose a huge amount of money in Forex trading and want to desperately win your trading losses back? Don't worry! This has happened to many traders before and there are people who have got back on track. Losing a huge fortune may appear to be an indication of the end of your Forex trading career but it doesn't have to be. Treat your previous losing streak as the greatest lesson that you have had and start all over again. The only thing you need to make sure is not to repeat the same mistakes that you have committed before.
Forex trading is a career that requires a good discipline, patience, emotional stability and hard work. When you loose a huge money for the first time, you might have done the trading blunders that new traders often make. If you are aware of those mistakes and ensure not to do them again, then no one can stop you from succeeding in Forex. But always keep in mind that success doesn't come overnight. It takes years and you have to accept this reality.
Below are few guided steps to pull your string back;
• Take a break to ensure that your mind is free from any regrets or other negative emotions, this will make you slowly unburden yourself from the past and give you the necessary courage and confidence to start trading again.
• Review the mistakes you did the last time, including lack of proper training, poor risk management, and poor emotional management. Make a list of beginner's mistakes in Forex and clearly understand how those mistakes can ruin a trading account... Check most of our previous articles for better understanding on some beginners mistakes so you can be properly guided.
• Refresh your knowledge in Forex, do demo trading and back testing for a few days and start with the small account first. Make sure that the account size gives you enough room to take risks, as you must never risk more than 2% of your capital. Once you start winning some trades, you will get a strong confidence.
FxSignals_Gold Team.