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
Каскадерский трюк показал водитель автомобиля #Range#Rover на ул. Стеценко.
По предварительным данным, водитель двигался по ул. Стеценко, в какой-то момент потерял управление над своим железным конём и вылетел на тротуар, после чего влетел в трамплин из снега и въехал в воздухе в бигборд. К счастью никто в этом ДТП не пострадал. Водитель утверждает, что ехал с разрешённой скоростью
🌎 In 2014, NASA’s Mars rover Curiosity recorded unusual low-frequency sounds on the Red Planet. These noises, called "pressure fluctuations," are caused by Martian winds interacting with the planet’s thin atmosphere and ground. Scientists detected these signals using a special instrument known as REMS, and the data helps track daily weather changes on Mars. ✨
#Mars⚡#soundspace⚡#rover
👉subscribe Interesting Planet
👉more Channels
#cplusplus#arducopter#ardupilot#arduplane#ardurover#ardusub#autopilot#auv#copter#drone#dronekit#mavlink#plane#robotics#ros#rov#rover#sub#uas#uav#ugv
ArduPilot is a powerful and open-source autopilot system that can control many types of vehicles, including drones, planes, helicopters, and even submarines. It offers features like autonomous flight modes, programmable missions, and support for various sensors and communication systems. This system is highly reliable and customizable, making it beneficial for users who need advanced control over their vehicles. It also has a strong community and extensive documentation, which helps users learn and improve their projects.
https://github.com/ArduPilot/ardupilot