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

Резултати

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

Пребарај: #sanaa

当前筛选 #sanaa清除筛选
Iran-USA war - Middle East

@mideastpress · Post #42276 · 10.04.2026 г., 22:29

🇾🇪🇾🇪Aerial View | Flood of Gratitude and Covenant ​Driven by the resolve of "Do not weaken," the certainty of "You are the superior," the vigor of "Go forth," and the might of "Strike them above the necks" ​ 🚩The million-man march: "In Gratitude to Allah and Celebration of Victory.. Our Squares are United Against Zionism." ​Location: Al-Sabeen Square, the Capital #Sanaa Date: 22 Shawwal 1447 | April 10, 2026 🚨@MideastPress✅

Hashtags

The new Esselunga campus for employees. Esselunga entrusts the Japanese architects of Sanaa with the creation of a new campus in the historic headquarters of Pioltello, redeveloping an abandoned area to create a 10 thousand square meter park, a kindergarten, a gym, a multipurpose center, a medical office and a historical archive. Architecture: Sanaa Location: Italy #arch_shovel#news#architecture#sanaa#italy

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #3476 · 17.10.2024 г., 03:15

#Breaking: Six American and British terrorist airstrikes targeted several areas in the north and south of #Yemen's capital, #Sanaa. Do NOT ask why you are hated across the world when YOUR tax money is dropped from #B2Spirit bombers on people's heads in #Yemen What do they tell you when you ask them "WHY ARE YOU BOMBING PEOPLE HALF WAY ACROSS THE WORLD?" I bet your leaders tell you they are "barbaric terrorists" exactly when you are playing on your smart phone the video of the burning tents in #Gaza at the hands of THE MOST BARBARIC terrorists to have ever roamed this earth..your Zionist Friends.

Marwa Osman/MidEaStream

@Marwa_OsmanLB · Post #4170 · 17.03.2025 г., 12:02

Yemeni Media reported that approximately 40 U.S. airstrikes targeting the capital, #Sanaa, as well as Saada and Al-Bayda, have resulted in an initial toll of 32 dead and over 100 wounded, the majority of whom are women and children. The strikes are expected to continue for weeks. Four airstrikes hit the Al-Jeraf neighborhood in northern Sanaa, killing ten people and injuring 13 others. Additional strikes targeted the Attan and Jarban areas in the Sanhan district of Sanaa province. In #Saada, reports indicate that airstrikes on two homes in the Qahza area, north of the city, led to a rising casualty count of ten dead and 13 wounded. Meanwhile, the U.S. Central Command (#CENTCOM) confirmed that it had carried out a series of airstrikes against "Ansarullah" targets across #Yemen. CENTCOM stated that the operations involved precision strikes, justifying them as measures to defend U.S. interests, deter adversaries, and restore freedom of maritime navigation. #RedSea#DonaldTrump