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
⚡️Toncoin: TON Nominated for Best Developer Ecosystem
#TON#developers
Toncoin has announced that TON has been nominated for the Best Ecosystem Program for Developers at the BeInCrypto 100 Awards 2025. Enthusiasts and supporters can participate in public voting to support this achievement.
Source: link
@tonlines
EVAA Celebrates TON Mainnet Anniversary
#TON#developers
EVAA marks the anniversary of The Open Network Mainnet, launched on May 26, 2021. Over four years, the TON ecosystem has flourished with the contributions of active developers and TON Core.
Source: link
@tonlines
Tonnel Network: Telegram’s Financial Growth through Strategic Partnerships
#Telegram#developers
Tonnel Network highlights how Telegram’s financial stability has been strengthened through strategic partnerships with developers. These partnerships involve app and bot development, in-app purchases, and its advertising initiatives.
Source: link
@tonlines
We're a proud sponsor of the first Flow Hackathon – a global competition from 2/21–2/26 to push the limits of #web3#onFlow.
Beyond excited to be involved in the expansion of the #ecosystem and to provide an opportunity for developers to shine! 💡✨
This is what's up:
💰 $500K in prizes
🌐 Virtual & IRL events
📚 Education phase to learn more about building #onFlow
✨ Amazing speakers and judges
👨💻 Empowering #developers to do great things
Are you ready to build awesome innovations and earn prizes for your work?
Register today! 👇
https://hackathon.flow.com