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

Резултати

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

Пребарај: #freedomday

当前筛选 #freedomday清除筛选
Russian Consulate in Cape Town

@rusconct · Post #2506 · 27.04.2025 г., 16:47

🎉🇿🇦 Happy Freedom Day, South Africa! Today, 27 April, South Africa celebrates the 31st anniversary of its first democratic elections — a landmark event that marked the beginning of a new era of freedom, equality and justice. Held in 1994, these historic elections were the first in which citizens of all races could exercise their right to vote, putting an end to decades of apartheid rule. Freedom Day honours the sacrifices and courage of those who fought tirelessly against injustice and discrimination, paving the way for a democratic and inclusive South Africa. The Consulate General of the Russian Federation in Cape Town extends its warmest congratulations to all South Africans on this significant occasion! #FreedomDay#SouthAfrica

🇿🇦Freedom Day is a South African public holiday celebrated on April 27. 🎉 It commemorates the first democratic post-apartheid non-racial elections held on April 27, 1994, which led to the election of Nelson Mandela as President. 🇿🇦✨ These elections were the first where every South African citizen over the age of 18—including foreign residents—could vote. 📅 Freedom Day marks the end of colonialism and apartheid in South Africa. 🎥 Watch the video with English text: https://www.youtube.com/watch?v=6OKB8EoVqWc #History#Culture#Holidays#FreedomDay#Apartheid#SouthAfrica

Reuters: World

@reutersworldchannel · Post #149215 · 11.10.2021 г., 14:41

Sydney celebrates 'Freedom Day' after lockdown Sydney's cafes, gyms and restaurants welcomed back fully vaccinated customers on Monday after nearly four months of lockdown, as Australia aims to begin living with the coronavirus and gradually reopen with high rates of inoculation. #Sydney#FreedomDay#Lockdown#SydneyReopens#Australia#News#Reuters Subscribe: http://smarturl.it/reuterssubscribe Reuters brings you the latest business, finance and breaking news video from around the globe. Our reputation for accuracy and impartiality is unparalleled. Get the latest news on: http://reuters.com/ Follow Reuters on Facebook: https://www.facebook.com/Reuters Follow Reuters on Twitter: https://twitter.com/Reuters Follow Reuters on Instagram: https://www.instagram.com/reuters/?hl=en ➖@reutersworldchannel➖