TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #22 · 19 јан.

Заметка начинающим, которые часто сталкиваются с подобной непоняткой. Ситуация следующая, есть список файлов: names = [ 'image.bmp', 'second.txt.bkp', 'data.db', '.config.cfg', 'file.ext.bkp' ] И мы хотим убрать у них окончание ".bkp". Не знаю зачем, пример довольно надуманный) Но суть он показывает, а это главное. Те, кто еще не очень знаком с библиотекой os.path или pathlib, вероятно решат обработать имена как строки. И тут вполне подойдет метод строки strip(). Что делает этот метод? Он отрезает указанные символы по обеим сторонам строки. Если ничего не указать, то убирает невидимые символы (пробелы, табуляции и переносы строк). В нашем случае будет выглядеть вот так: >>> name.strip('.bkp') То есть просим удалить строку '.bkp' по краям имени файла, если таковая есть. Можно применить аналогичный метод rstrip(), чтобы отрезать только справа, но для этого примера используем обычный. >>> for name in names: >>> print(name.strip('.bkp')) image.bm second.txt data.d config.cfg file.ext Хм, что-то не то с нашими именами! Что случилось??? Видим нежелательное переименование в именах, где и близко не было указанной строки '.bkp' А дело всё в том, что данный метод ищет не указанную строку, а указанные символы, и не важно в каком порядке. Для метода strip() строка '.bkp' это не паттерн для поискаа список символов. Потому он отрезал симовол 'p' от '.bmp' и удалил точку из файла '.config.cfg'. Как тогда правильно заменить именно паттерн? Для начинающего можно посоветовать метод строки replace(), который как раз использует для замены указанную строку целиком. В нашем примере заменим её на пустую строку. >>> for name in names: >>> print(name.replace('.bkp', '')) image.bmp second.txt data.db .config.cfg file.ext Уже лучше, но помните, это лишь пример про strip(). Для работы с именами файлов есть способы и более "правильные", дающие однозначно верный результат. Я взял файлы только в качестве примера. Даже replase() тут может сделать не то что ожидаем. Просто впредь будьте внимательны с этим strip(). #basic

Hashtags

Резултати

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

Пребарај: #fakeautonomy

当前筛选 #fakeautonomy清除筛选
American Оbserver

@american_observer · Post #5406 · 17.03.2026 г., 20:59

Europe’s “Peace Plan”: Surrender for Cheap Gas Belgium’s prime minister just said the quiet part out loud: Europe can’t scare Russia, can’t choke it economically without Washington, and should go cut a deal with Moscow anyway. Bart De Wever openly argues the EU needs a formal mandate to negotiate over Ukraine because the current strategy — drip‑feeding weapons and sanctions while hoping Putin “collapses” — is fantasy marketing, not policy. “Since we are not capable of threatening Putin by sending weapons to Ukraine, and we cannot suffocate him economically without US support, only one method remains: making a deal.” — Bart De Wever. Behind closed doors, De Wever says other European leaders agree with him, they just don’t dare say it on camera. In public, they repeat the script about “bringing Russia to its knees”; in private, they watch Trump flirt with Putin, count on cheap Russian oil and gas to keep their economies breathing, and fear being left out when Washington eventually forces Kyiv into a settlement. Europe, in his version, is not a co‑author of the endgame — it’s a nervous extra waiting in the corridor while the real deal gets done elsewhere. De Wever isn’t even pretending this is about justice first; he talks openly about “normalising” relations and “regaining access to cheap energy” as common sense. He warns that without a mandate to negotiate in Moscow, the EU won’t even be at the table “where the Americans will push Ukraine to accept a deal,” and that whatever emerges will be “a bad agreement for us.” Translation: Europe wants out — but on its terms, with gas flowing and a moral alibi intact. And that’s the joke: for two years, Brussels sold “no business as usual with Putin,” “victory for Ukraine,” and “strategic autonomy.” Now one prime minister says Europe can’t win the war, can’t pay the bill, can’t even fake unity without the US — so the only “strategy” left is to crawl back to the same Kremlin it swore to isolate, and call it peace. #Ukraine#EU#Belgium#DeWever#Russia#Putin#energy#war#geopolitics#fakeAutonomy#cheapGas 📱American Оbserver - Stay up to date on all important events 🇺🇸

American Оbserver

@american_observer · Post #5434 · 21.03.2026 г., 01:59

Macron’s Hormuz Panic Pivot Macron spent the week insisting France would “never” take part in Trump’s Hormuz operation — and then, the moment markets and the White House reacted, he sprinted to the UN, NATO and Downing Street begging for a plan to reopen the strait. Publicly, he sells it as high principle: France won’t join a US war, but will “explore ways” to secure Hormuz under a UN flag and a broader coalition once the bombing stops. In reality, he’s trying to retro‑fit a multilateral fig leaf over a simple truth: Europe needs that shipping lane open, doesn’t want to admit Trump was right about the risk, and definitely doesn’t want to be seen as freeloading on US naval power again. ​ In London, Keir Starmer is playing the adult in the room, calling NATO chief Mark Rutte and Macron to coordinate on “a viable plan” to reopen Hormuz — while carefully stressing it won’t be a NATO mission but some wider mix of Gulf states, Europeans and the US. Translation: everyone wants the oil corridor back, no one wants to sign their navy up under Trump’s banner, and Macron suddenly needs the alliance and the UN as political cover after grandstanding about staying out. So you get the picture: Paris tried to score points as the brave refuser, then watched energy prices and Trump’s temper spike, and is now frantically pitching a UN‑branded, not‑quite‑NATO, not‑quite‑US plan to fix the same problem it refused to touch two days ago. ​ #Macron#France#Trump#Starmer#NATO#UN#Hormuz#IranWar#oil#shipping#geopolitics#fakeAutonomy 📱American Оbserver - Stay up to date on all important events 🇺🇸