TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #191 · 14 дек.

Как разделить строку с shell-командой на отдельные аргументы в виде списка? Если сделать просто сплит по пробелу то получим то что надо, кроме случаев со вставками текста с пробелами. Например так: >>> '-arg "I Am Groot"'.split(' ') ['-arg', '"I', 'Am', 'Groot"'] Чтобы учитывать текст в кавычках как единый аргумент можно воспользоваться функцией shlex.split() Кто читает мой канал давно, уже в курсе. А что делать, если нужно обратное действие? Объединить аргументы из списка в строку и при этом добавить кавычки в аргумент с пробелами. Конечно, если вы используете subprocess то он сам всё разрулит. Но если вам нужна именно команда одной строкой, то можно воспользоваться готовой функцией в том же subprocess. >>> from subprocess import list2cmdline >>> list2cmdline(['-arg', 'I Am Groot']) '-arg "I Am Groot"' Он также позаботится об экранировании уже имеющихся кавычек >>> list2cmdline(['-arg', 'I Am "Groot"']) '-arg "I Am \"Groot\""' А вот так он может "схлопнуть" в команду JSON >>> list2cmdline(['--json', json.dumps({'key': 'value'})]) '--json "{\"key\": \"value\"}"' _______________ Возможно кто-то спросит, а зачем соединять аргументы в строку если subprocess сам это сделает а os.system не наш путь? Мне как-то потребовалось отправлять команду на удалённое выполнение и в API поддерживалось указание команды только строкой. Так что всякое бывает) #libs#basic

Hashtags

Резултати

Пронајдени 23 слични објави

Пребарај: #legend

当前筛选 #legend清除筛选

Один из ключевых летних привозов для поклонников электронной музыки состоится 19 июля. Алматы впервые посетит именитый японец ¥ØU$UK€ ¥UK1MAT$U, который является яркой фигурой андеграунда Японии. Его выступление в Алматы станет последним в рамках его летнего тура. BONUS that we deserve: https://www.youtube.com/live/WvyvwlowHWM?si=21Q6cN70A6szW6W6&t=1357 -- -- -- -- @AlmaDvizh#legend#epic#dj

Interesting Planet 🌍

@interesting_planet_facts · Post #1099 · 04.12.2025 г., 18:11

🌎 The Aztec legend of Quetzalcoatl describes a feathered serpent god who brought knowledge and culture to people. Spanish chronicles report Aztecs believed Quetzalcoatl created humans by mixing his blood with ground bones from the underworld. ✨ #aztecs⚡#mythology⚡#legend 👉subscribe Interesting Planet 👉more Channels ​

Alexa Mods

@itsmealexaliza · Post #1056 · 10.10.2024 г., 08:11

India has lost a legend today. Ratan Tata, an extraordinary industrialist, visionary, and humanitarian, has left us. His contributions to the business world and society are unparalleled. He was not just a leader but an inspiration, embodying humility, integrity, and compassion. The legacy he built through the Tata Group and his philanthropic efforts will continue to inspire generations to come. Rest in peace, Ratan Tata Sir. You will forever be in our hearts. 🙏 #RIPRatanTata#Legend#EndOfAnEra”

News and Tips

@NewsAndTipsNT · Post #4028 · 27.01.2026 г., 02:42

My brother Pavel Durov! 💪 In a world where governments are tightening their grip on our freedoms, big respect to Pavel Durov, the unbreakable force behind Telegram! This man is a true fighter: exiled from Russia for refusing to sell out user data, building an empire on privacy and free speech, and now calling out the EU’s “war against privacy” with their impossible rules that punish innovation. He’s warning us we’re running out of time to save the free internet from a dystopian nightmare of surveillance and censorship. Even after his arrest in France and being blocked from speaking at freedom forums, he stands firm, removing harmful content without compromising principles. Pavel, you’re a legend and you are inspiring entrepreneurs and rebels everywhere to never back down. You are a dear friend and a loyal brother and I stand alongside you all the way 100%! #PavelDurov#FreeSpeechWarrior#Telegram#Legend - Conor McGregor

12
ПретходнаСтраница 1 од 2Следна