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

Резултати

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

Пребарај: #africom

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

@addisstandardeng · Post #21173 · 24.01.2026 г., 06:41

News: Deputy #US Secretary of State to visit #Ethiopia, meet PM Abiy, #AU chair US Deputy Secretary of State Christopher Landau is set to visit Ethiopia as part of a regional tour that will take him to #Egypt, #Kenya, and #Djibouti between January 24 and February 1, the US Department of State announced. According to a statement issued by the Office of the Spokesperson, Landau will travel to Ethiopia alongside the Commander of US Africa Command (#AFRICOM), General Dagvin Anderson. During his visit to Addis Abeba, Landau is expected to promote opportunities for US commercial engagement with the Ethiopian government and the private sector. The statement said the Deputy Secretary will also hold discussions with Ethiopian officials, including Prime Minister Abiy Ahmed, focusing on regional peace and security issues. In addition, he will meet with AU Commission Chair Mahmoud Ali... https://web.facebook.com/AddisstandardEng/posts/pfbid02NWzYTrBPpfi2CeqeE5sHCrXFz3UCj3kbNkHU7DBrk9396y48rFcgPGFrdrK2Yjoil

Addis Standard

@addisstandardeng · Post #21224 · 28.01.2026 г., 13:08

News: #PM_Abiy receives #US Deputy Secretary Christopher Landau, AFRICOM commander as #Ethiopia, US agree to deepen security cooperation Prime Minister Abiy Ahmed said he received a courtesy visit from US Deputy Secretary of State Christopher T. Landau and the Commander of the United States Africa Command (#AFRICOM), General Dagvin Anderson, describing the engagement as warm and constructive and underscoring the importance of continued collaboration and mutual respect between the two countries. The visit comes as part of a regional tour by Deputy Secretary Landau that includes #Egypt, #Ethiopia, #Kenya, and #Djibouti, scheduled to run from 24 January to 1 February. Earlier, Foreign Minister Gedion Timothewos held talks with Landau in Addis Abeba, with discussions focusing on strengthening bilateral relations and exchanging views on regional issues of mutual interest. During their stay, Landau and General Anderson also visited the International Aviation .... Read more: https://addisstandard.com/?p=54807

Addis Standard

@addisstandardeng · Post #21211 · 27.01.2026 г., 14:34

News: #US Assistant Secretary Christopher Landau, AFRICOM commander arrive in #Ethiopia, visit Air Force aviation expo U.S. Assistant Secretary of State Christopher Landau arrived in Ethiopia today as part of a regional tour that includes #Egypt, Ethiopia, #Kenya, and #Djibouti, scheduled to run from 24 January to 1 February. The Commander of the U.S. Africa Command (#AFRICOM), General Dagvin Anderson, is also in Ethiopia as part of the visit. Today, Landau and General Anderson visited the International Aviation Expo organized by the Ethiopian Air Force, according to the Ethiopian National Defense Force (#ENDF). Field Marshal Birhanu Jula, Chief of General Staff of the Ethiopian National Defense Force, also took part in the visit. The expo showcased aircraft, defense technologies, and related products from the Ethiopian Air Force, the Defense Engineering Industry Group,.. https://www.facebook.com/AddisstandardEng/posts/pfbid021qedgKswfSFzdABsQXmFSvjuiRtWQedXpLYXJysCdk1MBnWvdx4JZJTmEng9jPGRl

Addis Standard

@addisstandardeng · Post #21758 · 18.03.2026 г., 10:05

#US Forces conduct strike targeting ISIS-Somalia In coordination with the Federal Government of Somalia, U.S. Africa Command (#AFRICOM) conducted an airstrike targeting #ISIS-#Somalia on March 16, 2026. The airstrike occurred in the vicinity of the Golis Mountains, approximately 45 km southeast of #Bossaso. AFRICOM, alongside the Federal Government of Somalia and Somali Armed Forces, continues to take action to degrade ISIS-Somalia’s ability to threaten the U.S. Homeland, our forces, and our citizens abroad. Specific details about units and assets will not be released to ensure continued operations security. (Source: AFRICOM)

Addis Standard

@addisstandardeng · Post #21316 · 05.02.2026 г., 08:33

News: #AFRICOM signals deeper #US security, economic engagement in #East_Africa The Commander of the United States Africa Command (AFRICOM), General Dagvin R.M. Anderson said Washington is seeking to more closely align security cooperation with economic investment across #Africa, citing recent engagements in #Ethiopia, #Kenya, and #Djibouti as part of a broader strategy to address growing security threats while fostering stability and development. Speaking during a digital press briefing yesterday, General Anderson said he recently concluded a joint visit to East Africa with US Deputy Secretary of State Christopher Landau, where discussions focused on counterterrorism, regional security, and the link between stability and economic growth. In Ethiopia, Anderson said he attended the Black Lion Air Show marking the 90th anniversary of the Ethiopian Air Force, underscoring what he described as the long-standing US–Ethiopia security partnership.... Read more: https://addisstandard.com/?p=54989

Addis Standard

@addisstandardeng · Post #21278 · 02.02.2026 г., 12:27

#US shifts Al-Shabaab combat operations from #Djibouti to #Kenya? The United States and Kenya have launched a $71 million initiative to upgrade the airfield at #Manda Bay, a facility situated directly adjacent to the #Somali border. While the project focuses on infrastructure in Kenya, analysts view the move as part of a major strategic realignment by US Africa Command (#AFRICOM) to encircle Al-Shabaab threats originating from Somalia, while simultaneously reducing reliance on Djibouti. Countering Threats from Somalia The expansion involves extending the runway to 10,000 feet, allowing the base to support large cargo and military aircraft. This capability is designed to boost refueling options and rapid security responses for operations targeting militants in the Horn of Africa. General Dagvin R.M. Anderson of AFRICOM noted that the project strengthens the security alliance against regional threats.... https://www.ftlsomalia.com/us-shifts-al-shabaab-combat-operations-from-djibouti-to-kenya-somaliland/