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

Резултати

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

Пребарај: #hitsats

当前筛选 #hitsats清除筛选
Addis Standard

@addisstandardeng · Post #21162 · 23.01.2026 г., 08:07

Hunger, death, devastation: No respite in #Tigray a year after #US aid cuts Lately, 88-year-old Nireayo Wubet spends many of his days burying friends and family members. As he grieves, he worries about whether there will be anyone left to offer him a decent burial when the time comes, as severe hunger ravages a large swath of his village in #Ethiopia’s northern Tigray region. “We have little humanitarian support,” laments the octogenarian whose frail appearance is mirrored by many others in his village of #Hitsats, near the Eritrean border. “It’s not conflicts that will ultimately kill us, but famine,” he says. Once a proud farmer from Humera – currently a disputed area within the Amhara region – Wubet took shelter in Hitsats four years ago, after fleeing conflicts and ethnic strife that uprooted him and others in the region. He was first displaced in the middle of the Tigray war... https://web.facebook.com/AddisstandardEng/posts/pfbid0mMVb9ns8gPGCMXSzawQkMRcqY4uTyK2SaPPUr2g8J4ioE1DUjiRFq3AnYViNf4ghl

Addis Standard

@addisstandardeng · Post #21819 · 24.03.2026 г., 13:30

#Ethiopia: More than 1,300 IDPs died of hunger in #Tigray camps, official says More than 1,300 internally displaced persons (#IDPs) have died from hunger and lack of medical care in camps across Ethiopia’s Tigray region over the past three years, according to a regional official cited by AFP. Gebreselassie Tareke, a director at Tigray’s Social Affairs Office, told AFP that at least 1,309 people had died in IDP camps, warning that conditions are deteriorating amid declining humanitarian assistance. “The situation is getting worse,” he said, noting reduced support from both the federal government and international aid organizations. He added that one of the most affected camps hosts around 150,000 people, with many others at risk. Recent reporting by Addis Standard points to similar conditions on the ground. On 19 March 2026, it reported that at least 333 IDPs had died at the #Hitsats camp since May 2025 due to hunger & lack of medicine, while 125 deaths..... Read more: https://addisstandard.com/?p=56035

Addis Standard

@addisstandardeng · Post #21765 · 19.03.2026 г., 05:31

#Ethiopia: More than 330 IDPs reported dead in #Hitsats, 125 in #Adwa as coordinators warn of worsening humanitarian crisis At least 333 internally displaced persons (#IDPs) have died at the Hitsats center in Tigray since May 2025 due to hunger and lack of medicine, while in Adwa 125 people have died since October 2025. DPs and camp officials told Addis Standard that shrinking humanitarian assistance and continued new arrivals are pushing already vulnerable communities into what they describe as a life-threatening crisis, intensifying pressure on limited resources. Displaced residents and coordinators in Hitsats say the situation has further worsened, with rising fatalities, disease outbreaks, and reduced humanitarian support. “To speak of the conditions in Hitsats, one must see it with their own eyes,” said Abrha Mebrahtom, coordinator of the Hitsats IDP center. “Though there were good starts previously, they have now ceased. People are wasting away;..... Read more: https://addisstandard.com/?p=55953