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

Пребарај: #shire

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

@addisstandardeng · Post #21223 · 28.01.2026 г., 12:10

News: Over Birr 2.2 million seized in #Shire as authorities warn against illegal lending amid cash shortages Authorities in Shire Endaselassie city in the Northwestern Zone of #Tigray have seized more than Birr 2.2 million allegedly used for illegal money lending, amid warnings that usury is increasingly exploiting communities affected by persistent cash shortages. In a press statement issued on 27 January 2026, Deputy Inspector Gebre-Anenya Teklay, representing the Shire Endaselassie city police commander, said an individual was apprehended on 25 January in Kebele 04 after being caught in the act of distributing cash while charging interest rates of between three and five percent. The suspect was taken into custody along with the seized cash, he said. Deputy Inspector Gebre-Anenya described usury as a criminal offense under the law and a practice condemned by religious and cultural.... https://www.facebook.com/AddisstandardEng/posts/pfbid02A5LPW2jGC4PugMchMnHxqydpS4jq3qgXECZFWnKqUoK3hgrzwgWMFMuHWgQ9tTe4l

Addis Standard

@addisstandardeng · Post #21233 · 29.01.2026 г., 08:52

News: #Ethiopian Airlines suspends flights to #Tigray airports Ethiopian Airlines has suspended flights scheduled for today to airports in Tigray, including #Mekelle, #Axum, #Shire, and #Humera, according to information obtained by Addis Standard. An Addis Standard reporter on the ground in Mekelle confirmed airport staff were informed to take a break for the day. However, Ethiopian Airlines’ ticket office in Mekelle continued providing services, excluding flights scheduled for today. “The system is working. We are giving services. We sell tickets scheduled from tomorrow onwards. We reschedule flights and provide other services,” one ticket office staff member told Addis Standard. “But none of us know why flights were suspended today.” Passengers who had booked flights for today received text messages notifying them of the cancellation. One message sent to customers read: “Your flight ET0102 from ADD on 29 Jan 2026, at 08:10 AM has been cancelled…. Read more: https://addisstandard.com/?p=54824

Addis Standard

@addisstandardeng · Post #21289 · 03.02.2026 г., 08:43

News: #Ethiopian Airlines resumes flights to #Tigray after five day suspension Ethiopian Airlines has resumed flights to Ethiopia’s northern Tigray region after a five day suspension, with the first flight departing from Addis Abeba arriving at #Mekelle#Alula Abanega International Airport at 7:50 a.m., an Addis Standard reporter in Mekelle confirmed. The national carrier suspended flights to Tigray last Thursday, affecting airports in Mekelle, #Axum, #Shire, and #Humera, as tensions escalated in parts of the region. The suspension disrupted both passenger travel and cargo services, further constraining transportation links between Tigray and the rest of the country. An officer at the Ethiopian Airlines ticket office in Mekelle confirmed to Addis Standard on Monday that flights had resumed. Speaking on condition of anonymity, the official said services were expected to restart early... https://web.facebook.com/AddisstandardEng/posts/pfbid034oz7ko4wv6Pk4Uv3HhL6JZccVHUMcLUEZ7KLDT9LkHpPfDajkgvRPT5dxsXqoMRVl

Addis Standard

@addisstandardeng · Post #21254 · 30.01.2026 г., 14:55

News: Flights to #Tigray remain suspended, affecting even Interim Administration president’s scheduled Addis visit The continued suspension of #Ethiopian Airlines flights to Tigray has disrupted official travel, with Tigray Interim Administration President Tadesse Worede confirming that his planned visit to #Addis_Abeba did not take place due to the flight cancellations. Asked by Addis Standard whether his visit was hindered by the suspension of flights, President Tadesse responded, “Yes.” Flights to airports in Tigray, including #Mekelle, #Axum, #Shire, and #Humera, remained suspended on Friday, with Ethiopian Airlines yet to provide an official explanation for the disruption. An Addis Standard reporter on the ground confirmed airline ticket office, however, remained open... Meanwhile, road transportation in parts of Southern Tigray has also been disrupted. Transport movement along the #Woldiya–#Kobo–#Alamata corridor remains limited, while displacement Read more: https://addisstandard.com/?p=54856

Addis Standard

@addisstandardeng · Post #21964 · 07.04.2026 г., 12:56

News: Federal police charge suspected trafficking kingpin linked to deaths, abuse of migrants Addis Abeba —#Ethiopian Federal Police said it has referred to prosecutors the case of human trafficking kingpin #Yitbarek_Dawit (Kibrom) and nine accomplices, accused of orchestrating a cross-border network that trafficked more than 3,000 people and was linked to over 100 deaths and the rape of more than 50 women. In a statement, police said the suspect, described as an internationally wanted fugitive, was arrested in #Shire town in the #Tigray region following a coordinated operation conducted with the Regional Operational Centre in support of the #Khartoum Process. Authorities said the investigation involved extensive intelligence-sharing across multiple countries. Police said the suspect used multiple identities to evade capture, including names such as #Yitbarek Dawit Alemu, #Paulos Dawit Wolday, and aliases including #Adhanom, #Ahmed, #Munir, and Read more: https://web.facebook.com/share/p/1Arn3MFntC/