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
MASS VOTING ANNOUNCEMENT
Join us to secure another win for #BTS at Forbes. Collect Mple Points on Mnet plus. Lets show team work💪
🔸 9PM KST — Mass Trending
🔸 10PM KST — Mass Voting
RT to spread!
https://mnetplus.onelink.me/TRa8/xohkwx0b?custom_link_value=vote%2Fv2%2F69e1e4a93f2d83251ec7ae8f
🔔 | MCOUNTDOWN PRE-VOTE
"SWIM" by #BTS is nominated for MCOUNTDOWN PREVOTE. Voting is happening on Mnet Plus App.
Cast your 5x votes, ARMY!
End: March 24 | 11:59pm KST
🗳️: https://mnetplus.onelink.me/TRa8/xohkwx0b?custom_link_value=vote%2Fv2%2F69b9e1620a7f885e409fc4d8
📊| #BTS “SWIM” MV has surpassed 600k likes on Youtube & make sure to JOIN the premiere 10 minutes before the release time 🙌🏻
https://youtu.be/b4iVv91Z6lY?si=lPRS0EgrstGiXjOr
📊| #BTS “SWIM” MV has surpassed 500k likes on Youtube!
✅ JOIN Premier and LIKE the MV
https://youtu.be/b4iVv91Z6lY?si=zL9DiILbq8ku7QtZ
╭────────────────╮
⟭⟬ 𝗩홉| @Vhope_Uzb ≪
•❁•──────•❁•───────•
Billboard has conducted a poll about who should headline the 2027 Super Bowl Halftime show, and #BTS was included as one of the nominees
🗳 VOTE FOR BTS
https://www.instagram.com/stories/billboard/3829656382363279258?utm_source=ig_story_item_share&igsh=MTU1dzVicGUzMGRuZA==
https://www.billboard.com/culture/tv-film/super-bowl-2027-halftime-show-poll-who-should-perform-vote-1236177216/
New Spotify message from #BTS for ARIRANG!💜
“Hey we are BTS!
We finally back with our 5th album ARIRANG. This album reflects the culmination of journey to date and define us on our own terms.
Make sure to pre save on Spotify! Thank you”
https://open.spotify.com/watch-feed/artist-videos?si=4grkbDV9QHyHvZk0a-pc6g&firstItemUri=spotify%3Aexpression%3A224Zn3cC3g1pirtomQ6qXv&pi=0063i2y4R0epO
🌏Global Goals - #BTS's "Permission To Dance On Stage" LIVE Album !
🚨RT AND SPREAD
📅July 18, 1PM (KST) | 0AM (ET)
🔗BTS.lnk.to/PTD-LIVE
🔗 Pre-save on Spotify:
https://open.spotify.com/prerelease/358phfp6OfvY7nO46mk94z
🔔 | MCOUNTDOWN PRE-VOTE
"SWIM" by #BTS is nominated for MCOUNTDOWN PREVOTE. Voting is happening on Mnet Plus App.
Cast your 5x votes, ARMY!
End: March 24 | 11:59pm KST
🗳️: https://mnetplus.onelink.me/TRa8/xohkwx0b?custom_link_value=vote%2Fv2%2F69b9e1620a7f885e409fc4d8
-@All_BTS_Updates
BTS reveals the tracklist and credits for their highly anticipated, upcoming album, “ARIRANG”, releasing on March 20!
1️⃣ Body to Body
2️⃣ Hooligan
3️⃣ Aliens
4️⃣ FYA
5️⃣ 2.0
6️⃣ No. 29
7️⃣ SWIM
8️⃣ Merry Go Round
9️⃣ Normal
🔟 Like Animaks
1️⃣1️⃣ They dont know bout us
1️⃣2️⃣ One more night
1️⃣3️⃣ Please
1️⃣4️⃣ Into the Sun
Each #BTS Member has multiple Composers/Songwriters credits on the album —
RM — 13
SUGA — 11
J-HOPE — 10
JungKook — 4
V and JIMIN — 2
-@All_BTS_Updates