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
#ComingSoon: An integrated development at Yew Tee which will house 2-room Flexi flats for seniors, a community club, a polyclinic, retail shops, and Choa Chu Kang’s first hawker centre all under one roof!
P.S. The 2-room Flexi flats will be launched in the upcoming November sales exercise, along with over 4,000 flats in Hougang, Jurong West, Kallang/Whampoa and Tengah 😊
(Photo credit: MKPL Architects)
🚨The SingSing Tycoon NFT Marketplace is on its way🚨
💥 Trade exclusive NFTs for profits.
💎 Flex your collection.
🎮 Unlock game-changing assets.
Get ready to take your SingSing Tycoon experience to the next level! 🚀
🔜 Your favorite NFTs, all in one place—stay tuned for more details 👀
#NFT#SingSingMarketplace#ComingSoon
🎤Announcement | Chat | X (Twitter) | Website | Game
🚀 Big News Alert 🚀
$SING is gearing up for an exciting CEX listing next week! 📈 But we’re keeping the exchange a secret…for now! 🤫
Guess the CEX & get ready for the reveal! 🔥
#SingSing#CEXListing#ComingSoon
🎤Announcement | Chat | X (Twitter) | Website | Game
Kaptaan | Official Teaser | Amazon MX Player
Language: Hindi
Genre: Drama, Crime, Thriller
jahan insaaf ki zarurat ho, wahan Kaptaan ki entry pakki hai ⚖️🔥
Kaptaan, coming soon, only on Amazon MX Player for FREE!
watch now🔗- https://youtu.be/X4Kb6K7B61o
#Kaptaan#AmazonMXPlayer#ComingSoon
Famously Fit with Sophie | Official Trailer | Amazon MX Player
Language: Hindi
Genre : Fitness based Chat Show
Bollywood fitness secrets, finally out 👀
Famously Fit with Sophie, coming soon only on Amazon MX Player for FREE!
watch now - https://youtu.be/Cs6lCuRgBC8
#AmazonMXPlayer#ComingSoon#FamouslyFitwithSophie
🔜 Exciting partnership announcement coming soon! 🎉
Can you guess who will be integrating SingSing's SocialFi SDK next? 🤔
Stay tuned for the big reveal! 🚀✨
#Partnership#SocialFi#SingSing#ComingSoon
📢CLOSED BETA WHITELIST CLOSED
Attention, QuasarK Community: the application period for our closed beta is now officially closed. We want to express our heartfelt thanks ❤️ to everyone who applied and showed their interest in being a part of this exclusive testing phase. Your support and enthusiasm mean the world to us! 👏
🚀 But hold on tight, because the journey is just getting started! In a matter of days we’ll be reaching out to our whitelisted beta testers🏆. If you made it to the whitelist, keep an eye on your notifications and direct messages 📩 as we will be sharing important updates and instructions with you. BEWARE OF SCAM!
Stay tuned for more updates and announcements 👀 as we continue to make progress towards the launch of QuasarK. We appreciate your ongoing support and look forward to embarking on this exciting journey together!
#QuasarK#ClosedBeta#BetaTesters#ComingSoon