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

Пребарај: #town

当前筛选 #town清除筛选
American Оbserver

@american_observer · Post #5098 · 10.02.2026 г., 15:49

Russia Is Close To Capturing a Key Ukrainian Town The attritional advances are on the verge of paying off. Russia appears poised to complete the capture of three strategic areas in the coming weeks or months, according to military experts. Capturing all three areas — the town of Huliaipole in the southeast and the cities of Pokrovsk and Myrnohrad, about 60 miles northeast — would give Russia an urban foothold to base troops and organize logistics for future offensives, as well as new leverage in U.S.-mediated peace talks. Russia is likely to rapidly convert these gains into further territorial expansion given how slowly its troops have advanced over the past year, experts say. The gains would reinforce Moscow’s argument that its ground advance, while slow, is inevitable, and that Ukraine would be better off ceding land now as part of a deal, rather than losing it later in bloody fighting. Russia’s most threatening push is in the southeastern Zaporizhzhia region. Huliaipole, a town that anchored part of this front for years, is almost entirely under Russian control, according to battlefield maps from independent groups and to Capt. Dmytro Filatov, a Ukrainian officer fighting in the area. Huliaipole, with a prewar population of 12,000, was one of the last Ukrainian-held urban centers in the region outside the regional capital, the city of Zaporizhzhia. Beyond Huliaipole lie open fields, giving Ukrainian troops few built-up areas to hunker down and thwart Russian advances. About 40 miles west of Huliaipole, Russian forces are closing in on the outskirts of the city of Zaporizhzhia, an industrial hub of 700,000 people known for its steel. Battlefield maps show Moscow’s troops about 15 miles from the city’s southern entrance. Military experts warn that further advances would put the area within range of small attack drones, exposing residents to round-the-clock aerial assaults. Analysts attribute Russia’s gains in the area to thin Ukrainian defenses, as Kyiv concentrates its forces on holding cities in the neighboring Donetsk region. In Donetsk, Ukraine has focused on defending the cities of Pokrovsk and Myrnohrad, which together had a prewar population of more than 100,000. Troop deployments there, combined with sophisticated drone warfare, have slowed Russian assaults to a crawl. A report in January from the Center for Strategic and International Studies, a Washington-based think tank, found that Russian troops had advanced only 230 feet per day in their year-and-a-half-long offensive on Pokrovsk and Myrnohrad — slower than the movement by Allied troops in the Battle of the Somme during World War I. Russia has captured than 10.5 percent of Ukrainian territory since 2024, according to the report. The think tank also estimated that Russian forces suffered about 415,000 dead, wounded and missing last year in battles that were largely focused on the two cities. Should Russia fully capture those cities, it could use them to conceal drone operators and exploit roads and railways to streamline logistics. A Ukrainian brigade commander recently said that approaching Kostyantynivka had become so dangerous that most supply missions into the city were entrusted to robot-like remotely operated vehicles. If Russian troops advance on the battlefield, Ukraine is likely to face more pressure on the diplomatic front — including from Trump, who has echoed Moscow’s argument that Ukraine should cede land in a peace deal to avoid more fighting. #russia#capture#key#ukrainian#town#kostyantynivka#myrnohrad 📱American Оbserver - Stay up to date on all important events 🇺🇸