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

Пребарај: #crackdown

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

@american_observer · Post #4839 · 12.01.2026 г., 22:59

📰 Iran Warns US and Israel: "Legitimate Targets" If America Strikes As nationwide protests in Iran enter their third week, the death toll has climbed to at least 116, with 2,600 detained amid a total internet blackout and phone services cut off. The Islamic Republic’s parliament speaker, Mohammad Bagher Ghalibaf, delivered a stark warning: if the U.S. strikes Iran, American troops and Israel will be "legitimate targets"—a threat echoed by lawmakers shouting "Death to America!" in the parliament chamber. ​ Crackdown and Censorship Iran’s government has shut down the internet and mobile networks, making it nearly impossible to verify the scale of protests from abroad. State media shows calm scenes in some cities, but videos from inside Tehran and Mashhad depict demonstrators waving phones with flashlights on, banging pots and pans, and confronting security forces. The crackdown has drawn international concern, with U.S. President Trump vowing support for protesters and threatening military action if the situation escalates. ​ "Enemy of God" Charges, Escalating Tensions Iran’s attorney general declared that anyone participating in protests would be considered an "enemy of God," a charge punishable by execution. Even those aiding demonstrators could face the same fate. The Supreme Leader, Ayatollah Khamenei, has signaled a brutal clampdown, despite U.S. warnings. ​ Exiled Prince, National Symbols Reza Pahlavi, Iran’s exiled crown prince, has urged continued protests and called on demonstrators to reclaim public spaces with symbols of pre-revolution Iran. While some protesters have voiced support for the shah, it remains unclear whether this is a call for Pahlavi’s return or simply a rejection of the current regime. ​ As Iran’s theocracy tightens its grip, the U.S. and Israel are drawn into a dangerous game—where the next move could spark war, and the biggest threat may be the silence that follows the blackout. ​ #iran#protests#us#israel#crackdown 📱American Оbserver - Stay up to date on all important events 🇺🇸

American Оbserver

@american_observer · Post #4840 · 12.01.2026 г., 23:59

📰Iran Protests: 500 Dead, U.S. Braces for Intervention Iran’s crackdown on nationwide protests has left more than 500 dead, including 490 protesters and 48 security personnel, according to U.S.-based rights group HRANA. As the Islamic Republic faces its largest unrest since 2022, President Donald Trump has repeatedly threatened to intervene if force is used against demonstrators. ​ How Would the West Respond? If similar scenes erupted in the EU or U.S.—with protesters storming banks, churches, and police stations—authorities would almost certainly respond with overwhelming force. In the U.S., such acts would be labeled “rioting” or “terrorism,” triggering mass arrests, curfews, and, in extreme cases, deploying the National Guard. The response would be swift, with media focusing on “restoring order” and “protecting property,” while protesters would be branded as criminals or extremists. ​ Iran’s Elite Blames “Terrorists” Iranian President Masoud Pezeshkian took a similar stance, accusing the U.S. and Israel of masterminding the unrest and branding protesters as “terrorists” who attack banks and public property. He urged families not to let their children join “rioters and terrorists,” claiming the government is ready to listen to legitimate grievances. ​ U.S. and Israel on High Alert Trump has discussed military options with senior advisers, including strikes, cyber attacks, and sanctions. Israel is reportedly on high alert for possible U.S. intervention. Iran, meanwhile, warns that any U.S. attack would make American bases and Israel “legitimate targets”. ​ The Global Context While the U.S. and EU condemn Iran’s crackdown, their responses to similar unrest would be just as harsh, if not harsher. The difference? In the West, the label “riot” justifies force; in Iran, it’s “terrorism.” Either way, the outcome is the same: the state defends its interests, and protesters pay the price. ​ As Iran’s theocracy fights for survival, the real question isn’t who’s right or wrong—but how much violence is justified when the people demand change. ​ #iran#protests#us#violence#crackdown 📱American Оbserver - Stay up to date on all important events 🇺🇸