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

Пребарај: #cryptoconference

当前筛选 #cryptoconference清除筛选

Blockchain Life 2025, Dubai | October 28–29 The 15th anniversary edition of Blockchain Life is set to become the largest crypto event of the year for those building careers and businesses in the Web3 space. With over 15,000 attendees expected, the forum will feature three content stages and a vibrant open-air program. Five reasons to get this on your schedule.: 1️⃣Positioning for the next market phase. Industry experts will share growth scenarios and actionable steps to help you make the most of the upcoming cycle. 2️⃣First-hand tech trends. Industry leaders will present innovations that could go mainstream within months. Simultaneous translation into Russian will be available. 3️⃣Global networking. With representatives from funds, exchanges, and infrastructure projects, the event is a powerful platform for partnerships, investment, and career opportunities. 4️⃣Expanded program. In addition to the main forum, expect themed meetups, yacht tours, and exclusive evening events. 5️⃣Atmospheric AfterParty. As tradition goes, the organizers will bring in top international performers — the lineup will be announced closer to the date. 🎟Get your ticket with a 10% discount here using promo code TONEVENTS 🚬See you in Dubai! #BlockchainLife2025#Dubai#CryptoConference#Web3#CryptoNews

Blockchain Life 2025, Dubai | October 28–29 The 15th anniversary edition of Blockchain Life is set to become the largest crypto event of the year for those building careers and businesses in the Web3 space. With over 15,000 attendees expected, the forum will feature three content stages and a vibrant open-air program. Five reasons to get this on your schedule.: 1️⃣Positioning for the next market phase. Industry experts will share growth scenarios and actionable steps to help you make the most of the upcoming cycle. 2️⃣First-hand tech trends. Industry leaders will present innovations that could go mainstream within months. Simultaneous translation into Russian will be available. 3️⃣Global networking. With representatives from funds, exchanges, and infrastructure projects, the event is a powerful platform for partnerships, investment, and career opportunities. 4️⃣Expanded program. In addition to the main forum, expect themed meetups, yacht tours, and exclusive evening events. 5️⃣Atmospheric AfterParty. As tradition goes, the organizers will bring in top international performers — the lineup will be announced closer to the date. 🎟Get your ticket with a 10% discount here using promo code TONEVENTS 🚬See you in Dubai! #BlockchainLife2025#Dubai#CryptoConference#Web3#CryptoNews