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
The Daily Gwei (🔗YouTube)
🔗ETH infinite bid, Ethereum's next 10 years and more - The Daily Gwei Refuel #845 - Ethereum Updates
Subscribe to the newsletter: https://thedailygwei.substack.com
Follow me on Twitter: https://twitter.com/sassal0x
Follow The Daily Gwei on Twitter: https://twitter.com/thedailygwei and https://twitter.com/DailyGwei_TV
Join the Discord channel: https://discord.gg/4pfUJsENcg
--------------------------------------------------
The Daily Gwei Refuel gives you a recap every week day on everything that happened in the Ethereum and crypto ecosystems over the previous 24 hours - hosted by Anthony Sassano.
--------------------------------------------------
Timestamps and links 👇
00:00 Introductory song
https://x.com/sassal0x/status/1955246612789465572
01:40 ETH treasury companies on fire
https://x.com/SERdotxyz/status/1955458142977810600
17:14 The ETH ETFs seeing record flows
https://x.com/sassal0x/status/1955461999862878368
23:21 The SEC's...
View original post
~
₿izFeed#⃣:#daily
OKX XP Marathon - S3
Run the long game 🏃🏻♀️🏃🏻♀️🏃🏻♀️
Prize:
250 USDT waiting for you to win!
🥇 1st : 60 USDT
🥈 2nd : 50 USDT
🥉 3rd : 40 USDT
🎁 4th : 30 USDT
🎁 5th : 20 USDT
🎁 6th–10th : 10 USDT each
How to earn points👇
1. Sign up on OKX (If you haven’t already)
2. Join & stay in OKX Global Discord (Must)
3. Chat actively in #general-chat to earn XP🏆 and use the hashtag # XPMarathonS3
4. Valid messages only (No spam, No links)
5. Send 'Win XP' to #daily-check-in to earn extra points 👉 100xp
6. Submit this Form for reward distribution
📆 Event Period: 4/2/2025, 9:30 AM - 13/2/2026, 6:00 PM (GMT+8)
👇
Join now
Our Socials:
⚜️Sign Up on OKX | Join Affiliate | TG | DC | Wallet TG | Wallet Announcement | OKX on Spotify | Twitter/X | YouTube
⭐️CN DC | CN TG
‼️Please check the authenticity of all OKX links or channels at OKX channel verification