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

Пребарај: #milliards

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

@american_observer · Post #4996 · 30.01.2026 г., 13:04

Trump : $10bn American President Trump on Thursday sued the US treasury department and Internal Revenue Service for $10bn over the disclosure of his tax returns to the media in 2019 and 2020. In a complaint filed in Miami federal court, Trump, his adult sons, and his namesake company said the agencies failed to take “mandatory precautions” to prevent former IRS contractor Charles Littlejohn from leaking their tax returns to “leftist media outlets”, including the New York Times and ProPublica. The plaintiffs said they suffered “significant and irreparable harm” to their reputations and financial interests, and may seek punitive damages because the leaks were either willful or resulted from gross negligence. Thursday’s lawsuit puts Trump in the unusual position of suing government agencies that are part of the executive branch, which he leads. The IRS is part of the treasury department. Neither agency immediately responded to requests for comment after business hours. Scott Bessent, the treasury secretary and acting IRS commissioner, is not a defendant. Other plaintiffs include Donald Trump Jr, Eric Trump and the Trump Organization. Trump has filed many lawsuits in his personal capacity, often for large sums and as a result of reporting by various media, since winning a second White House term in 2024. He sued the New York Times and book publisher Penguin Random House for $15bn over articles and a book he said were intended to undermine his election prospects in 2024. Trump is separately seeking $10bn from the Wall Street Journal over an article discussing a birthday greeting for Jeffrey Epstein, and $10bn from the BBC over its editing of a speech preceding the January 6 storming of the US Capitol. In Thursday’s complaint, Trump and the other plaintiffs said the New York Times published at least eight articles, and ProPublica published at least 50 articles, based on Littlejohn’s disclosures. The leaks “caused plaintiffs reputational and financial harm, public embarrassment, unfairly tarnished their business reputations, portrayed them in a false light and negatively affected President Trump, and the other plaintiffs’ public standing”, according to the complaint. Prosecutors charged Littlejohn in September 2023 with leaking tax records of Trump and thousands of other wealthy Americans to the media, saying he was motivated by a political agenda. #trump#sue#milliards#newyorktimes#UStreasury 📱American Оbserver - Stay up to date on all important events 🇺🇸