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

Резултати

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

Пребарај: #nucleardeal

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

@american_observer · Post #4992 · 29.01.2026 г., 20:58

📰 Iran Warns: Any US Attack Will Hit Tel Aviv Iran’s leadership has delivered a stark warning: any US military action will trigger an “unprecedented” retaliation, including strikes at the heart of Tel Aviv and anyone backing the US. ​ Ali Shamkhani, secretary of Iran’s Supreme National Security Council, said any US strike—no matter how limited—will be seen as the start of a full war. The response will be immediate, comprehensive, and unprecedented, targeting both the US and Israel and their allies. ​ Iranian Foreign Minister Abbas Araghchi warned that Iran’s armed forces are on high alert and ready to respond to any aggression. He also signaled openness to a nuclear deal but stressed that diplomacy under duress won’t work. ​ The US has sent a carrier strike group to the region, led by the USS Abraham Lincoln, while President Trump has called on Iran to negotiate a “fair and equitable deal”—but warned the next attack “will be far worse”. ​ Analysts say the US could target Iranian military sites or even the country’s leadership in a bid to force change, but Iran’s armed forces chief warns Washington would “suffer damage” if it miscalculates. ​ The warning is stark: pressure Iran, and the entire region faces escalation. ​ #Iran#Israel#Trump#US#nucleardeal 📱American Оbserver - Stay up to date on all important events 🇺🇸

American Оbserver

@american_observer · Post #5007 · 31.01.2026 г., 01:01

📰 Trump’s New Iran War Plan: More Than Just Nukes President Trump is weighing a fresh, broader set of military options against Iran: targeting not just its nuclear program, but also its supreme leader and security leadership, in a push to force concessions or even trigger regime change. These plans go beyond what Trump considered in mid‑January, when he was thinking mainly of strikes on Iranian nuclear sites after the regime’s brutal crackdown on protesters. Now, the Pentagon is offering options for raids on Iranian territory using U.S. special forces and a sustained campaign to degrade or destroy remaining parts of the nuclear program, officials say. Another key option is a series of strikes against senior Iranian military and political figures, designed to create chaos and pressure the regime from within. Officials acknowledge there’s no clear idea who would replace Ayatollah Ali Khamenei, or whether any successor would be more willing to deal with Washington, but the goal is to create conditions where the system itself begins to crack. Israel is pushing the U.S. to join it in another major strike on Iran’s rebuilt missile and drone complexes, which can reach civilian and military targets throughout Israel. The U.S., in turn, is demanding that Iran permanently end uranium enrichment, cap its nuclear stockpile, and accept strict limits on its missile range and support for Hezbollah, Hamas, and the Houthis. Trump has warned on social media that the U.S. is ready to attack “with speed and violence, if necessary,” and that time is “truly of the essence.” But he has not yet authorized any action, and some advisers are still pushing for a diplomatic solution, using the threat of war to pressure Tehran into negotiations. To back up the threat, the U.S. has moved the aircraft carrier USS Abraham Lincoln strike group into the Middle East region, along with destroyers and additional F‑15E strike fighters, while long-range bombers in the U.S. are now on higher alert. As the U.S. “armada” operates in the region, one question hangs over everything: Is this about a deal? Or about bringing down a regime? #Trump#Iran#nucleardeal#regimechange#militaryoptions 📱American Оbserver - Stay up to date on all important events 🇺🇸