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

Резултати

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

Пребарај: #peaceagreement

当前筛选 #peaceagreement清除筛选

በደቡብ ጎንደር ዞን ታች ጋይንት በጫካ ሲንቀሳቀስ የቆየው ታጣቂ ቡድን የሰላም ጥሪውን ተቀበለ *************** በአማራ ክልል መንግሥት እና በአማራ ፋኖ ሕዝባዊ ድርጅት (አፋሕድ) መካከል የተደረሰውን አዲስ የሰላም ስምምነት ተከትሎ ራሱን "የገብርየ ክፍለ ጦር" በማለት ሲጠራ የቆየው ታጣቂ ቡድን የሰላም ጥሪውን ተቀብሏል። በአማራ ክልል በደቡብ ጎንደር ዞን ታች ጋይንት ወረዳ፣ በጫካ ሲንቀሳቀስ የቆየው ታጣቂ ቡድኑ፤ የመንግሥትን የሰላም ጥሪ በመቀበል ወደ ሰላማዊ እንቅስቃሴ ተመልሷል። ይህ ውሳኔ በክልሉ ለረጅም ጊዜ የቆየውን የትጥቅ ግጭት በውይይትና በሰላም ለመፍታት የተያዘውን አዲስ አቅጣጫ በተግባር መሬት ያወረደ ትልቅ እርምጃ ሆኖ ተመዝግቧል። ለቡድኑ አባላት በተዘጋጀው የአቀባበል መርሐ ግብር ላይ የደቡብ ጎንደር ዞን የብልፅግና ፓርቲ ቅርንጫፍ ጽሕፈት ቤት ኃላፊ አቶ መንበር ክፈተው፣ የሀገር መከላከያ ሠራዊት ከፍተኛ አመራሮች፣ የዞንና የወረዳ አመራሮች እንዲሁም የአካባቢው ማህበረሰብ መገኘታቸውን የአማራ ኮሙኒኬሽን መረጃ ያመላክታል። #Ethiopia#PeaceAgreement#AmharaRegion#SouthGondor#Peace

Crypto M - Crypto News

@CryptoM · Post #64748 · 09.04.2026 г., 17:55

🚀 U.S. President Donald Trump Anticipates Imminent Peace Agreement with Iran U.S. President Donald Trump has conveyed a positive outlook regarding the potential for a peace agreement with Iran. According to NS3.AI, Trump believes that negotiations are progressing favorably, suggesting that a resolution may be reached soon. This development comes amid ongoing diplomatic efforts to address tensions between the two nations. The President's remarks highlight a significant shift in the geopolitical landscape, with implications for international relations and regional stability. #DonaldTrump#Iran#PeaceAgreement#Diplomacy#InternationalRelations#Geopolitics#MiddleEast#Negotiations#RegionalStability

Crypto M - Crypto News

@CryptoM · Post #65299 · 12.04.2026 г., 15:34

🚀 Iran Expresses Readiness for Regional Peace Agreement Iranian President Ebrahim Raisi has expressed the country's readiness to establish a balanced and fair agreement to ensure lasting peace and security in the region. According to BlockBeats, this statement was made during a phone conversation with Russian President Vladimir Putin on April 12, as reported by Iran's Tasnim News Agency. #Iran#EbrahimRaisi#VladimirPutin#RegionalPeace#Security#PeaceAgreement#IranRussia#BlockBeats#TasnimNews

Crypto M - Crypto News

@CryptoM · Post #64518 · 09.04.2026 г., 05:44

🚀 Middle East Ceasefire Expected to Hold Despite Fragility Jefferies global economist Mohit Kumar has stated that despite the fragility of the Middle East ceasefire agreement, it is expected to hold. According to Odaily, Kumar noted that both parties have reached a point where they desire a ceasefire, as continued conflict would negatively impact both sides. Kumar highlighted that U.S. President Donald Trump is keen on reaching an agreement, as he lacks support from his core base for ongoing warfare. Meanwhile, the Iranian Revolutionary Guard faces challenges due to economic devastation, potentially paving the way for future uprisings. He concluded that given the interests of both parties, the unstable ceasefire is likely to persist. #MiddleEast#Ceasefire#MohitKumar#US#Iran#DonaldTrump#Conflict#RevolutionaryGuard#GlobalEconomics#PeaceAgreement#Odaily

Crypto M - Crypto News

@CryptoM · Post #64768 · 09.04.2026 г., 21:01

🚀 STOCKS | S&P 500 Rises for Seventh Day Amid U.S.-Iran Peace Deal Optimism The S&P 500 extended its gains for the seventh consecutive session, buoyed by growing optimism about a potential long-term peace agreement between the U.S. and Iran. Wall Street Journal (Markets) posted on X, highlighting the positive sentiment among investors as diplomatic efforts continue to progress. The sustained rally in the S&P 500 reflects investor confidence in the potential easing of geopolitical tensions, which could have significant implications for global markets. Analysts suggest that a successful peace deal could lead to increased stability in the region, potentially benefiting various sectors, including energy and defense. As negotiations advance, market participants remain attentive to developments that could influence future market movements. #SP500#USIranPeaceDeal#WallStreet#GeopoliticalTensions#MarketOptimism#EnergySector#DefenseSector#InvestorsConfidence#GlobalMarkets#PeaceAgreement#DiplomaticEfforts

Addis Standard

@addisstandardeng · Post #21764 · 18.03.2026 г., 16:31

Premiering now: The Standard Signal | Ep.14: Tigray on the Brink: Survival, Famine Risks, and the Shadow of Renewed War in Ethiopia. Click here to watch: https://www.youtube.com/watch?v=YDjUomfsWnA Tigray is facing fragile recovery, deepening humanitarian strain, and growing fears of renewed war. In this episode of The Standard Signal, Duke Burbridge shares what he witnessed on the ground — from survival and displacement to aid challenges and famine risks. #StandardSignal#EthiopiaPolitics#ONLF#Ogaden#PeaceAgreement#PoliticalRepression#ShrinkingCivicSpace#ResourcePolitics#OilAndGas#Federalism#DemocracyInEthiopia#HornOfAfrica#Accountability#PoliticalDialogue#Tigray