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

Пребарај: #ogcommunity

当前筛选 #ogcommunity清除筛选
MoonPlay

@moonplay_official · Post #40 · 24.06.2024 г., 18:59

New Partnership Announcement: MoonPlay x OGCommunity!🚀 Hey Space Cadets! Kick-starting this week with the announcement of our partnership with👾OGCommunity - a powerhouse in the gaming industry with over 2 million members. They have something for everyone: communication with like-minded people, learning something new, earning money, investing, influencing the development of the industry, developing and launching projects in gaming, taking part in eSports tournaments, and playing the most exciting games. Together, we’re set to elevate your gaming experience to cosmic heights! 🔝 What This PartnershipMeans for You: 👥Enhanced Community: Benefit from the expertise and influence of one of the most impactful communities in gaming. 💸New Opportunities: Discover unique ways to earn, invest, and play, brought to you by the combined efforts of MoonPlay and OGCommunity. ✅Industry Influence: Be part of a movement that shapes the future of gaming, supported by a robust ecosystem of projects and initiatives. Together with OGCommunity, we’re bringing more excitement, innovation, and opportunities to your space adventures. Stay tuned for more updates 👀 as we embark on this stellar journey together! Stellar adventures start here:@moon_land_bot🚀 JOIN OGCOMMUNITY: ✉Channel ❌Twitter 🤖Discord *⃣Linktr.ee🐝Blog🐝OGC App #ToTheMoon#OGCommunity#MoonPlay#partnership#ecosystem#blockchain#gamefi#web3#wenlisting#airdropsoon#communityfirst#taptap#clicker#game

MoonPlay

@moonplay_official · Post #67 · 16.07.2024 г., 17:33

New Mission Pack Alert 👀 OGCommunity, known for building the most influential community and ecosystem in the gaming industry, brings you a fresh pack of missions! Connect with over 2 million members 👥, gain new knowledge, and take part in epic gaming experiences. 👉 Head right to Missions tab and complete special tasks curated by OGCommunity to earn rewards. Don't miss out on this opportunity. Together, we’ll conquer the cosmos and build a thriving lunar colony! 🤩 👉Start your To The Moon adventure now!👈 Website | Telegram Chat | X | Discord | Medium #ToTheMoon#MoonPlay#OGCommunity#ecosystem#blockchain#gamefi#web3#wenlisting#squad#mission#communityfirst#taptap#clicker#game