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 the spiral galaxy NGC 3310, astronomers have observed a rare "gamma-ray burst afterglow," the fading embers following one of the universe’s brightest explosions. This lingering glow, seen in visible light and X-rays, lets scientists track how shockwaves from the original burst plow through space, revealing clues about the powerful forces unleashed when massive stars die. ✨
#gamma-ray-bursts ⚡#strange-cosmic-phenomena ⚡#galaxies⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
"Nunca habíamos visto nada igual..."
Algo aterrador está sucediendo en Estados Unidos (2025)
Únase a nosotros: https://anon.news
🔘En este video, el mundo quedó atónito ante la repentina aparición de un elegante monolito metálico en los remotos desiertos de Utah.
Alto y silencioso, el objeto guardaba un asombroso parecido con los monolitos de 2001: Odisea del Espacio, y luego, con la misma incógnita, desapareció.
Desde entonces, han aparecido docenas de estructuras similares en lugares de todo el mundo, desde las montañas nevadas de Rumania hasta las playas de California, las selvas de Colombia y los tejados de las ciudades europeas.
¿Son instalaciones artísticas, engaños elaborados o algo más enigmático?
Cada monolito parece surgir sin previo aviso, a menudo en lugares de difícil acceso, y sin que nadie se atribuya la responsabilidad.
Algunos son espejados y minimalistas; otros están grabados con símbolos crípticos.
El fenómeno ha desatado la intriga mundial, generando teorías de conspiración, videos virales y un auge en el debate especulativo sobre la vida extraterrestre, las sociedades secretas y la conciencia colectiva.
#unexplained#strange#phenomena
@EndTimesProductions@Jaymez
🪐 One of the most mysterious cosmic events are gamma-ray bursts, or GRBs—brief, intense flashes of high-energy light detected from distant galaxies, like the spiral galaxy NGC 2770. In 2008, NGC 2770 hosted the rare GRB 080319B, which was so bright that, for about 30 seconds, it was visible to the naked eye from Earth despite being 7.5 billion light-years away, making it the most distant object ever seen without a telescope. ✨
#gamma-ray-bursts ⚡#strange-phenomena ⚡#NGC2770⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels
🪐 In the star-forming region W51, astronomers have found “masers”—natural lasers made of microwaves—blasting out intense, focused beams from clouds of water and methanol molecules. These cosmic masers shine thousands of times brighter than any similar emission in our solar system and act like celestial signposts, marking areas where massive new stars are being born within dense, hidden clouds of gas. ✨
#strange⚡#phenomena⚡#maser⚡#starbirth⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space
👉subscribe Universe Mysteries
👉more Channels