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

Резултати

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

Пребарај: #herlegacy

当前筛选 #herlegacy清除筛选
Bloom Org

@bloomorg_uz · Post #45 · 31.05.2025 г., 16:56

#LetHerBloom#HerLegacy 🌸 Today, we are coming back with our rubric “Her Legacy”, where we dive into lives of women who changed not only theirs, but millions of other women’s lives. Bloom will tell you who Malala is, her global impact, her achievements, and why she inspires us. 🪄She is the one who taught us that one voice can change revolutions. Remember: ✨One spark can cause fire that millions of people cannot stop. Be that spark! 💜 Let’s change the world together! Let’s get the strength and change OUR lives. And after all, Let Her Bloom! 🚀Telegram | 📷Instagram

Bloom Org

@bloomorg_uz · Post #10 · 25.04.2025 г., 18:04

#LetHerBloom#BloomTogether#MentalHealthAwareness#AbusePrevention#HerLegacy 🌸Introducing Bloom’s New Rubric Series🌸 We’re launching a fresh series of posts to raise awareness, educate, and create conversations that matter. Here’s what you’ll see on our page: ✨ Abuse 101 – A breakdown of the different types of abuse. 🚩⏺ Red & Green Flags – What’s healthy vs. what’s harmful in relationships. 🧠 Mental Health Impact – The emotional cost of abuse. 🤝 If You Think Someone’s Being Abused – What to do and how to help. 💐 Her Legacy – Stories of powerful women who changed the world. 🌿 Healthy Boundaries – Why they matter and how to set them. 🎬 Feminism in Media – Representation, reality, and rewriting the narrative. Stay tuned, stay aware, and let’s keep growing together 🌱💜 🚀Telegram📷Instagram