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

Пребарај: #rogachev

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

@rusconct · Post #1765 · 01.08.2024 г., 16:56

LESSONS OF HISTORY REPEATED ✍️Article by Ambassador of Russia to South Africa Ilya Rogachev (31 July 2024) READ IN FULL Key points: 🔹 Obsessed with the idea to inflict a military defeat upon Russia and split it into several smaller states with limited sovereignty, the collective West is heading towards a war against Russia, and decisions of the latest NATO summit in Washington D.C. corroborate that. "Europe is preparing for war. The pro-war train has no brakes, and the driver has gone mad” - Hungary’s Premier V.Orban". 🔹There is a very common opinion in Russia that approximately once in a centenary, the West braces up and comes to the Russian soil with a sword, where it gets beaten up and retires with its nose bloodied to remain calm for another 100 years. 🔹The Time of Troubles in Russia (XVII century) was accompanied by foreign military interventions (Poland, Sweden) which endangered the very existence of Russia as a sovereign state. But in 1612 people’s militia ousted the invaders. 🔹The XVIII century saw yet another major clash with Europeans known as the Great Northern War. During Swedish King Charles XII’s Russian campaign, in 1709, the army of invaders was completely decimated by Russian troops under the command of Peter the Great. 🔹In about 100 years, a new attempt to clamp Russia was made as Napoleon Bonaparte of France in 1812 led his ‘Grand Army’ into the ill-fated invasion. 600,000 soldiers of his army came to Russia in June 1812, and in only 6 months their remnants were chased away by Field Marshal Kutuzov’s troops. In 1814, the Russian army entered Paris. 🔹The XX century saw another large-scale invasion of Russia from the West. Our country survived World War I accompanied by inner political turmoil with three revolutions, the Civil War and foreign military interventions involving UK, France, USA etc. ☝️ Only two decades later Nazi Germany attacked the USSR. Hitler intended to conquer the USSR by the end of 1941, but it didn’t turn out the way he expected. On 30 April 1945, as the Red Army was storming Berlin, he committed suicide in the basement of the Reich Chancellery. 👉 Russian historian V.Klyuchevsky once wrote that history does not teach any lessons but punishes one for not learning them. The West should stop rewriting history and start learning it, in order to prevent history from repeating itself every 100 years. #alternativeviewpoint#embassyofrussia#rogachev#russia#southafrica