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

Резултати

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

Пребарај: #plantatree

当前筛选 #plantatree清除筛选
Go! Announcements

@gorwachain_announcements · Post #226 · 24.10.2023 г., 17:08

🌱 Going Green: Planting Trees and Promoting Sustainable Living in the Go! Game 🌍🌳 Hello Go! Community, We're excited to share our latest eco-friendly initiative within the Go! Game: The "Plant a Tree" Quest! 🌱🚶‍♂️ 🌿 How It Works 🌿: For every 25,000 steps you complete, the Go! Project will plant a real tree in partnership with organizations dedicated to reforestation and sustainable living. 🌳 It's a fantastic way to make your wellness journey even more impactful! 🌿 Why This Matters 🌿: Environmental Impact: Together, we're reducing our carbon footprint and contributing to a healthier planet. Motivation: Planting a tree adds an extra layer of motivation to hit your step goals. Real-World Impact: Beyond personal wellness, you're making a real, tangible difference in the world. 🌿 How to Join 🌿: ➡️ Open the Go! app and make sure your step tracker is connected. ➡️ Sync your step tracker and start walking! ➡️ For every 25,000 steps, you'll be notified of the tree planted in your name. Are you ready to step up your wellness journey while contributing to a greener, healthier Earth? 🌏👣 Join on https://chat.goplatform.io now! 🌍🌱 #PlantATree#SustainableLiving#EcoFriendly🚶‍♀️🌳