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

Пребарај: #schoolgirls

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

@american_observer · Post #5303 · 06.03.2026 г., 13:45

Who Killed Iranian Schoolgirls? Military investigators believe it is likely that US forces were responsible for an apparent strike on an Iranian girls’ school that killed scores of children on Saturday but have not yet reached a final conclusion, according to two US officials. Reuters was unable to determine further details about the investigation, including what evidence contributed to the tentative assessment, what type of munition was used, who was responsible or why the US might have struck the school. The Pentagon chief, Pete Hegseth, on Wednesday acknowledged the US military was investigating the incident. Two US officials, who spoke on condition of anonymity to discuss sensitive military matters, did not rule out the possibility that new evidence could emerge that points to another responsible party. The girls’ school in Minab, in southern Iran, was hit on Saturday during the first day of US and Israeli attacks on the country. Iran’s ambassador to the UN in Geneva, Ali Bahreini, said the strike killed 150 students. Reuters could not independently confirm the death toll. The Pentagon referred questions to Central Command, whose spokesperson, Capt Timothy Hawkins, said: “It would be inappropriate to comment given the incident is under investigation.” The White House did not directly comment on the investigation, but its press secretary Leavitt said in a statement: “While the Department of War is currently investigating this matter, the Iranian regime targets civilians and children, not the United States of America.” Asked during a news briefing on Wednesday about the incident, Hegseth said: “We’re investigating that. We, of course, never target civilian targets. But we’re taking a look and investigating that.” Rubio told reporters on Monday that the US would not deliberately target a school. “The Department of War would be investigating that if that was our strike, and I would refer your question to them,” Rubio said. Israeli and US forces have, until now, divided their attacks in Iran geographically and by target type, a senior Israeli official and a source with direct knowledge of the joint planning said. While Israel was striking missile launch sites in western Iran, the US was attacking similar targets, and naval ones, in the south. The UN human rights office has called for an investigation into the attack on the school, without saying who it believed was responsible. Deliberately attacking a school or hospital or any other civilian structure would probably be a war crime under international humanitarian law. If a US role were to be confirmed, the strike would rank among the worst cases of civilian casualties in decades of conflicts in the Middle East. #iranian#schoolgirls#killed#us#israel 📱American Оbserver - Stay up to date on all important events 🇺🇸