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
🌙#Hashtag’chilarim, ulugʻ ayyom - Qurbon hayiti muborak!
🐑 Keltirilayotgan qurbonliklar dargohida qabul boʻlsin.
✈️ Eng yaxshi tilaklar va albatta, eng yangi gadjetlarni tilab qolaman.
😎Hurmat bilan, JM!
Hammaga salom!
Ha, ancha yo'q bo'lib qoldim, postlar qo'yilmadi, ijod qilinmadi. Sabablar yetarlicha, afsuski.
Kuz fasli oilamiz uchun quvonarli kelib, o'g'il farzandli bo'lgandim. Kuz oxiriga kelib esa Otam bilan bog'liq kutilmagan fojea yuz berib, 29-oktyabrda reanimatsiyaga tushib qoldilar. Allohning irodasi ekan, 46 kunlik og'ir betoblikdan keyin Otam 14-dekabr kuni vafot etdilar...
Shu-shu, dafn marosimlari bilan ovora bo'lib, o'zimning sog'ligim va halovat yo'qligi bois kanalga yangilik joylashtira olmadim. Lekin, hayot davom etarkan. O'zimda kuch to'plab, sekin-asta ishga, ijodga qaytyapman. Shu sabab, sizning qo'llab-quvvatlab turishingiz zarur menga.
Rahmatli Otamni sizlarga keyinroq batafsil tanishtirmasam bo'lmaydi. Chunki ular #Hashtag blogimning qandaydir ma'noda asoschisi ham. 6 yoshligimdan qo'limga "payal'nik" berib, tranzistor-u diodlarni, kondensator va rezistorlarni tanishtirgan, birinchi radio, robotlarimni yasashni o'rgatgan aynan Otam - Bekpo'lat o'g'li Faxriddin!
Adamni ohirati obod bo'lsin, Jannatlarda uchrashish nasib etsin. Duolaringizda eslab qo'ysangiz, sizdan minnatdorman. 🤲🏻
⚠️ Endi 9/11 men uchun yomon sana emas!
🎉 Bu xursandchilikni sizlar bilan bo'lishgim keldi. Bugun oilamizda "kichkina #hashtag" dunyoga keldi, Alhamdulillah.
🤲 InshaAllah yurtimizga, dinimizga xizmat qiladigan o'g'il bo'lsin. "Ayti" bo'yicha bilimi kuchli, sportdayam tengsizlar qatorida bo'lib, O'zbekiston bayrog'ini yuqoriga ko'p marotaba ko'tarishini niyat qildim (orada bayrog'imizni Oyga, Marsga qo'yishini ham o'yladim, to'g'risi 😅)
☺️ Oldindan bildiriladigan tilaklar va tabriklar uchun rahmat, #Hashtag oilasi!
🏆 OKX Bounty Hunt New Season #2🏆
Engage, Refer & Win!
Prize:
- $400 USDT weekly allocation
🥇 $80 | 🥈 $60 | 🥉 $40
4th to 6th - $20
7th to 10th - $15
11th - 20th - $10
How to earn points:
✅ Check In Daily -> GM OKX Fam #OKXBountyHuntNewSeason#2 every day 👉50000
✅ Chat & Engage - Chat actively (30+ characters) 👉30
✅ Invite Friends - 🔗 Tag Admins to get your personal invite link and invite more people to join OKX Announcement👉50
✅ Share your reactions/emojis under the announcement posts
Check points🏆
Bounty points
Bounty ranking
More points!
👉 Share pictures and topics of New Year and crypto with the #hashtag in the chat
Join the event now👇👇👇
OKX Bounty Hunt New Season #2 Form
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
🏆 OKX Bounty Hunt New Season #1🏆
Engage, Refer & Win!
Prize:
- $400 USDT weekly allocation
🥇 $100 | 🥈 $50 | 🥉 $30
4th to 6th - $20
7th to 10th - $15
11th - 20th - $10
How to earn points:
✅ Check In Daily -> GM OKX Fam #OKXBountyHuntNewSeason#1 every day 👉50000
✅ Chat & Engage - Chat actively (50+ characters) 👉20
✅ Invite Friends - 🔗 Tag Admins to get your personal invite link and invite more people to join OKX Announcement👉50
✅ Inviters earns extra 👉 10 per message sent by the invitee
✅ Share your reactions/emojis under the announcement posts
Check points🏆
Bounty Points
Bounty Ranking
More points!
👉 Share pictures and topics of New Year and crypto with the #hashtag in the chat
Join the event now👇👇👇
OKX Bounty Hunt New Season #1 Form
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
Chat-Specific Hashtags. Groups and channels can use the new format#hashtag@username for hashtags – which only show posts and stories from the same chat when tapped.
October Features
1 • 2 • 3 • 4 • 5 • 6 • 7 • 8 • 9 • More