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

Пребарај: #slextokens

当前筛选 #slextokens清除筛选
SLEX NEWS

@slex_io · Post #158 · 15.02.2024 г., 06:52

🚀The Time Is UP: Today is the First Day of SLEX Launchpad Sale! ☄️ ⚡️The wait is over! The first SLEX Launchpad officially starts today, February 15th at 12:00 UTC, after our Whitelist successfully closed with over 4000 participants. This marks the beginning of exceptional earning opportunities for our community🎉 🔥Premier Project Access: SLEX token holders, get ready for exclusive access to Tier-1 crypto projects. These handpicked projects offer a rare chance to invest in potentially profitable tokens. 💰Maximize Your Earnings: participate in the Launchpad to unlock staking rewards and additional trading benefits on SLEX Exchange. 📅 Important Reminder for Whitelist Members: 👀Due to the fact that token allocation and the time of the sale are limited, we recommend to deposit funds on your account in advance. ✍🏻If you did not create an account on SLEX yet, make sure that you create one under the email you specified in the Whitelist application form to be able to participate in token sale. #SLEX#LaunchpadLive#SLEXTokens#SLEXLaunchpad#SLEXWhitelist Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter

SLEX NEWS

@slex_io · Post #155 · 13.02.2024 г., 14:27

🚀Let the Sale Begin: The first SLEX Launchpad for 4000 Participants Starts on February 15th! 🎉 ⚡️We are thrilled to announce that the Whitelist on SLEX has been successfully closed with more than 4000 participants. And now we are at the finish line because it's only two days until the launch of the much-anticipated SLEX Launchpad!⚡️ 📈Mark your calendars and prepare to join SLEX Launchpad to get access to exceptional ways of earning: 🔥Access to Tier-1 Projects: SLEX token holders will gain exclusive access to Tier-1 projects, offering a gateway to the most promising and innovative crypto projects. 💰Staking Rewards and Trading Benefits: Token holders can get rewards from staking and additional trading bonuses at SLEX Exchange. 📅 If you are a Whitelist member check out email for more details and instructions about participation in the first SLEX Launchpad! #SLEX#LaunchpadAnnouncement#CryptoInnovation#SLEXTokens#TradingBenefits#SLEXLaunchpad#SLEXWhitelist Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter