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
💨 Nothing on the road will scare you after this
🇸🇪 In Sweden, driving schools teach students how to handle a car in all kinds of tricky conditions.
🚗 And yes — passing a skid-control test is mandatory before they can even get their license.
#driving@Car_News
🚗🇺🇸1 IN 3 US PARENTS FEAR TEEN DRIVERS WILL CAUSE DEADLY CRASH
🔹 University of Michigan poll: 33% worry their young driver could cause accident — but 96% think their kid drives "average or better" 🤔📊
🔹 Half (51%) witnessed unsafe behavior: 44% saw aggressive driving, 25% caught texting while driving, 17% saw impaired/sleepy driving 😱🚨
🔹 Only 24% imposed consequences — most just take keys (6%), refuse car (8%), or threaten insurance cuts (6%) 🔑💳
🔹 Parents who saw road rage LESS likely to rate teen as bad driver — massive blind spot putting lives at risk 🙈💀
American teens NOT ready for the road. Where are the parents? 😬🛣️
#USNews#teensafety#driving
@america
J-j家j谱p- 家谱 The Family Tree (2011)
直达链接:https://pan.quark.cn/s/32c4d8126f28
#家谱#The Family Tree #Driving Lessons
链接:https://link3.cc/sf_com
#电影#喜剧#美国#10年代
🔥🏁Koenigsegg Regera Breaks Rimac Nevera's Record in 0-400-0 Challenge 🏁🔥
🏆 The music didn't play for long: Rimac Nevera's record in the 0-400-0 km/h acceleration-braking challenge lasted only a month. The Croatian hypercar surpassed the previous record holder, Koenigsegg Regera, clocking in at 29.94 seconds.
🇸🇪 The Swedish brand shrugged and sent the Regera back onto the track. Guess what? 28.81 seconds. How do you like that, Mate Rimac?
🥇 The margin of victory was 1.13 seconds, which in such a discipline, it must be said, is quite impressive. Surely, Rimac will have to respond. Competing is possible, but it will definitely require some effort.
🏎️Interestingly enough, the Regera has already been discontinued, with the last unit delivered to its owner in 2022. So why set a record with a car that is no longer in production? Koenigsegg answers bluntly: "Because it can!" The Regera remains superior to any newcomer. And it has proven it once again.
💥To outperform a significant rival - an electric car that has just set 23 records - is both impressive and beautiful. 💥
#Koenigsegg#Regera#driving#car