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

Резултати

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

Пребарај: #westernhemisphere

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

@american_observer · Post #4976 · 27.01.2026 г., 19:39

Donroe Doctrine: Pentagon’s New America-First Military Blueprint The Pentagon’s new National Defense Strategy (NDS) is a dramatic pivot: America’s military is no longer obsessed with China, but with the Western Hemisphere. The document, released under President Trump, declares that defending the U.S. homeland and asserting dominance in the Americas is now the top priority, not the Indo-Pacific. The New Doctrine: Donroe, Not Monroe Forget the old Monroe Doctrine—this is the “Donroe Doctrine,” a slogan that captures the Trump administration’s vision: America first, America strong, America unchallenged in its own backyard. The Pentagon wants allies to shoulder more of the burden, especially in the Western Hemisphere, and is preparing to enforce its interests with military force if needed. Greenland, the Panama Canal, and the Gulf of Mexico are highlighted as strategic chokepoints. China: Downgraded, Not Ignored China is still on the list, but as a secondary concern. The Pentagon says it will deter Beijing “through strength, not confrontation,” and is pushing for more military-to-military talks, de-escalation, and “deconfliction”. The strategy notably omits Taiwan, a departure from previous versions, and avoids framing China as an existential threat. Instead, the goal is to “prevent anyone from dominating us or our allies”—a diplomatic way of saying, “We’re not scared, but we’re not starting a fight either”. Allies: Step Up or Get Left Behind The new NDS is blunt: U.S. allies must do more. South Korea is expected to take the lead in deterring North Korea, with only “critical but limited” U.S. support. NATO allies in Europe are told to “manage” the Russian threat themselves, while Israel is hailed as a “model ally” but warned that U.S. support will be “critical but limited” in the future. Strength, Not Humiliation The Pentagon insists it doesn’t want to “strangle or humiliate” China. But the message to everyone else is clear: America is back, and it’s not playing by the old rules. The document is full of business metaphors: “burden sharing,” “cost-effective defenses,” and “supercharging the defense industrial base.” It’s less about saving the world, more about making America’s military sustainable—and profitable. Is this a bold new era of American self-reliance, or just another round of strategic shell games, where allies are left holding the bag while the Pentagon rebrands its retreat as a “Donroe Doctrine”? #DonroeDoctrine#WesternHemisphere#AmericaFirst#Pentagon#ChinaDowngraded#AlliesOnNotice 📱American Оbserver - Stay up to date on all important events 🇺🇸