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
🌎 In ancient Chavín culture of Peru, intricate stone “pututu” conch trumpets echoed across ceremonial plazas. These natural shell horns carried sound up to a kilometer, uniting crowds during old rituals and feasts with their deep, haunting music. ✨
#history⚡#sound⚡#archaeology
👉subscribe Interesting Planet
🌎 The "Bloop" is one of the loudest underwater sounds ever recorded. Detected by NOAA hydrophones in 1997, this low-frequency noise was picked up over 5,000 kilometers apart. Scientists later identified melting icebergs as the likely source, not a sea creature or submarine volcano. ✨
#ocean⚡#sound⚡#mysteries
👉subscribe Interesting Planet
👉more Channels
🌎 Mysterious low-frequency sounds known as "The Upsweep" have been picked up by underwater microphones in the Pacific Ocean since 1991. This persistent sound rises and falls in pitch, lasts several seconds, and is strongest in spring and autumn. Its source remains unidentified, but some researchers suggest volcanic activity near the origin point may be involved. ✨
#ocean⚡#mysteries⚡#sound
👉subscribe Interesting Planet
👉more Channels
#sound
#неКуКураж_круче
#КультМедиа
Профессиональная команда дикторов возьмётся за озвучку любого ролика.
Каз/Рус/Муж/Жен.
От литературных текстов до делового стиля, портфолио предоставим.
Опыт озвучки: аудиокниги, анонсы телеканалов, имиджевые ролики крупных компаний и городов и проч.
wa/tg: +7 777 240 22 42
t.me/cult_media
🌎 The “singing” sands of select deserts produce eerie musical tones when walked on or disturbed. This haunting sound comes from millions of perfectly sized sand grains rubbing together and vibrating in harmony—nature’s own desert orchestra! ✨
#geology⚡#sound⚡#phenomenon
👉subscribe Interesting Planet
🌎 Strange cosmic "whistlers" recorded by satellites are caused by lightning on Earth. These radio signals travel along Earth's magnetic field, bounce off space, and return as high-pitched, descending tones—lasting less than a second. Some whistlers have been traced over thousands of kilometers from their original lightning strike. ✨
#space⚡#sound⚡#lightning
👉subscribe Interesting Planet
👉more Channels
🌎 Earth’s Schumann resonances are a set of naturally occurring, low-frequency electromagnetic waves circling the globe between the ground and the ionosphere. These “global hums” are mainly generated by lightning and pulse mostly at 7.83 Hz, serving as a natural radio background measured by scientists worldwide. ✨
#space⚡#sound⚡#atmosphere
👉subscribe Interesting Planet
👉more Channels
🌎 Some of the loudest natural sounds ever recorded in the ocean come from snapping shrimp, which use their oversized claw to shoot a high-speed bubble. When the bubble collapses, it creates a sound reaching 210 decibels—louder than a gunshot—and can stun small prey nearby. ✨
#ocean⚡#animal⚡#sound
👉subscribe Interesting Planet
👉more Channels
🌎 Jupiter’s magnetosphere produces “chorus” radio waves—sounds like twinkling or whistling—detected by NASA spacecraft. These signals are created by energetic electrons moving along the planet’s powerful magnetic field. The Juno probe recorded these plasma waves in 2016. ✨
#Jupiter⚡#space⚡#sound
👉subscribe Interesting Planet
👉more Channels
🌎 The Voyager 1 spacecraft captured “plasma wave” sounds as it entered interstellar space in 2012. These sounds are actually electromagnetic vibrations in space, converted into audio by NASA scientists. The pitch and intensity help scientists measure the density of charged particles beyond our Solar System. ✨
#Voyager⚡#space⚡#sound
👉subscribe Interesting Planet
👉more Channels