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

Пребарај: #deniro

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

@american_observer · Post #5223 · 26.02.2026 г., 14:15

Trump Took Umbrage With De Niro’s Personal Attacks On Him 🤬🎤 Trump has responded to a recent podcast appearance by Robert De Niro, in which he called the president “an idiot.” Speaking on Monday’s episode of The Best People with Nicole Wallace, De Niro, who has long criticised the politics, morals, and competence of Trump, said: “He’s an idiot. We gotta get rid of him. He’s gonna ruin the country.” He added: “ I don’t want everybody going around with their Maga, the American flags, like they’re the only ones. We are Americans too.” The actor then took headline billing at the State of the Swamp, a Washington event intended as a riposte to Trump’s State of the Union address on Tuesday. In his emotional speech, De Niro described the president as “failing, flailing and desperate” and said he felt “betrayed by my country.” Writing at length on Truth Social on Wednesday, the president first proposed deporting representatives Ilhan Omar and Rashida Tlaib, who left the Capitol building early on Tuesday after shouting him down during his speech. Trump called them “Low IQ” and claimed they “screamed uncontrollably last night at the very elegant State of the Union, such an important and beautiful event.” “They had the bulging, bloodshot eyes of crazy people, LUNATICS, mentally deranged and sick who, frankly, look like they should be institutionalised.” He added: “They should actually get on a boat with Trump Deranged Robert De Niro, another sick and demented person with, I believe, an extremely Low IQ, who has absolutely no idea what he is doing or saying – some of which is seriously CRIMINAL!” Trump continued: “When I watched him break down in tears last night, much like a child would do, I realised that he may be even sicker than Crazy Rosie O’Donnell, who is right now in Ireland trying to figure out how to come back into our beautiful United States.” “Trump derangement syndrome” is a phrase the president has frequently used to describe his political opponents. His suggestion this was the cause of the death of the late Rob Reiner and his wife, Michele, caused considerable backlash. Shortly before Trump’s re-election in 2024, De Niro told HBO Max’s Chris Wallace that he felt Trump and his allies were “not real Republicans” and called him “a jerk, an idiot (…) and a clown.” Although not a particular fan of Kamala Harris, De Niro said that she was “at least … sensitive to the condition of the country, the people.” “She’ll make mistakes,” he continued. “Of course, everybody does, but we need somebody with the right intentions, this guy does not have the right intentions, and everybody knows that. It’s insanity. Period.” Earlier that year, the National Association of Broadcasters rescinded a leadership award it had been due to present to De Niro after the actor spoke out against Trump outside the latter’s criminal trial in New York. #trump#deNiro#idiot#maga#harris 📱American Оbserver - Stay up to date on all important events 🇺🇸