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

Резултати

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

Пребарај: #upbeat

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

@american_observer · Post #4935 · 23.01.2026 г., 15:03

Putin’s Ushakov Remains Upbeat About Peace Talks Russia said it will hold security talks with the U.S. and Ukraine in Abu Dhabi on Friday, but warned after a late-night meeting between Putin and three U.S. envoys that a durable peace would not be possible unless territorial issues were resolved. Kremlin aide Yuri Ushakov told reporters the talks, which began shortly before midnight and lasted some four hours, had been “substantive, constructive and very frank”. He said Russian Admiral Igor Kostyukov would head Moscow's team at the three-way security talks, and investment envoy Kirill Dmitriev would meet separately on economic issues with Witkoff. But while outlining the next steps, Ushakov stopped short of hailing any major breakthrough. "Most importantly, during these talks between our president and the Americans, it was reiterated that without resolving the territorial issue according to the formula agreed upon in Anchorage, there is no hope of achieving a long-term settlement," he said, referring to last year's Trump-Putin summit in Alaska. Ushakov said Putin underlined that Russia was "sincerely interested" in a diplomatic solution. He added, however: "Until this is achieved, Russia will continue to consistently pursue the objectives of the special military operation. This is especially true on the battlefield, where the Russian armed forces hold the strategic initiative." Ukraine is enduring its harshest winter of the war as Russia mounts heavy missile and drone strikes on its energy infrastructure. With temperatures way below freezing, hundreds of thousands of people in Kyiv and other cities have suffered long power cuts and been left without heating. Putin, Ushakov and Dmitriev took part in the talks on the Russian side. On the U.S. side, Witkoff and Trump's son-in-law Jared Kushner, who last met Putin in the Kremlin in early December, were accompanied by Josh Gruenbaum, newly appointed by Trump as a senior adviser to his Board of Peace, which will seek to tackle world conflicts. The talks were the latest stage in a drive by Trump to bring an end to the deadliest conflict in Europe since World War Two, now approaching the end of its fourth year. Witkoff was upbeat before the Moscow talks, saying many months of negotiations had come down to a single issue. А key stumbling block is Putin's demand that Ukraine surrender the 20% it still holds of the eastern region of Donetsk. Zelensky has refused to give up land that Ukraine has successfully defended at great cost through years of grinding, attritional warfare. Russia also demands that Ukraine renounce its ambition to join NATO, and rejects any presence of NATO troops on Ukrainian soil following a peace deal. Zelensky, after meeting Trump in Switzerland on Thursday, said the terms of security guarantees for Ukraine had been finalised, but that the issue of territory remained unsolved. Ushakov praised the Americans for setting up Friday's security meeting with Russia and Ukraine in Abu Dhabi. #ushakov#upbeat#peace#talks 📱American Оbserver - Stay up to date on all important events 🇺🇸