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 слични објави

Пребарај: #tontix

当前筛选 #tontix清除筛选

🍿 TONTIX: $TNT presale is coming! TONTIX announced that very soon, a presale of $TNT tokenswill be conducted! This is a unique opportunity to become a part of this exciting project and support the development of a platform that will revolutionize ticket sales. 📊According to TNT tokenomics, 7% of the total token allocation will be dedicated to the presale. Buying the$TNT means gaining numerous benefits and investing in the future development of our project. The funds raised during this presale will be used to enhance the platform, expand our team, and advance our marketing efforts to reach a wider audience. 🎫Benefits of holding $TNT tokens: 🔵Exclusive Access: Token holders will have priority access to special events, promotions, and unique experiences. 🔵Voting Rights: Participate in the governance of TONTIX by voting on key decisions that shape the platform’s future. 🔵Rewards and Incentives: Earn rewards for your participation and engagement within the TONTIX ecosystem. 🔵Discounted Fees: Enjoy reduced service fees when purchasing tickets through the TONTIX dApp. 🔵Investment Potential: As the TONTIX platform grows, so too may the value of your tokens, offering potential for appreciation. Your participation will help the team to achieve this goal and shape the future of the ticketing industry. So don't miss the opportunity to join the project from the very beginning! Details about the date and terms of the presale will be announced very soon, so stay tuned for updates! 💙 Right now you can get 50 $wTNT as a reward for joining!✨ Chat | Website | Channel | Demo #tontix#presale#ticket#web3#NFT