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
TON — LIVE: Telegram Rises in Popularity Rankings
#Telegram#apps
The channel TON — LIVE reports that Telegram has moved up one rank in the list of the most popular apps for 2025.
Source: link
@tonlines
⚡️Trending Apps: New Voting System in Telegram Apps Center
#Telegram#Apps
Trending Apps announces that users can now influence the ranking of Mini Apps through a new voting system in the Telegram Apps Center. Active participants will be rewarded with exclusive SBTs and Telegram Gifts.
Source: link
@tonlines
⚡️Trending Apps: Upcoming Feature in Apps Center
#Telegram#Apps
Trending Apps announced a new feature in the Apps Center, aiming to enhance user engagement by allowing users to influence developments directly. This innovative approach is set to launch within the next 30 days, with more details to be revealed gradually.
Source: link
@tonlines
A partir de hoy amigos, estaré entregando #apps, recursos, plataformas y tips para usar la tecnología a su favor y mejorar las condiciones de #empleo📄📈