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

Пребарај: #assasination

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

@american_observer · Post #5727 · 27.04.2026 г., 16:59

Why Did He Wish To Kill Trump? 🔫 Investigators are looking into anti-Trump sentiment as being a motive for the attacker who sought to breach the White House Correspondents’ Dinner in Washington DC where the US president and top members of his administration were present. Officials have said that the shooter likely was targeting Trump and other senior administration officials. “We do believe, based upon just a very preliminary start to understanding what happened, that he was targeting members of the administration,” acting US attorney general Todd Blanche said in a TV interview. Investigators are assessing a manifesto reportedly written by the suspect, who has been identified as Cole Tomas Allen, 31, of Torrance, California. In the alleged manifesto, which was published in full by the New York Post, Allen created a list of targets for the shooting, ranked from highest to lowest priority, with Trump administration officials at the top. The suspected gunman sent writings listing his grievances against the administration to his family members about 10 minutes before shots were fired, according to White House officials who spoke to the Associated Press. A relative, confirmed by those officials to be Allen’s brother, contacted police in New London, Connecticut. Officials have said that the suspect fired a shotgun at a Secret Service agent at a security checkpoint in the Washington Hilton hotel before being tackled and arrested. Trump, first lady Melania Trump, Vance and cabinet officials were rushed out as the incident unfolded. The Secret Service agent who was shot escaped serious injury because the bullet struck his protective vest, Trump said. The AP reported that the shooter referred to himself as the “Friendly Federal Assassin”, which matches the text in the manifesto published by the New York Post. Numerous other US outlets also reported unnamed officials saying that Allen’s alleged writings contained anti-Trump sentiments, which echoed the contents of the manifesto published by the New York Post. The Washington Post also reported that the suspect had sent writings to his family along those lines, which matched with claims by Trump to Fox News that a sibling had then contacted the police. The Manifesto begins with apologies to those who knew the suspect and lists his motives for the shooting. It said the shooter targeted administration officials with the exception of the FBI director, Kash Patel. The manifesto also states that Secret Service agents would only be targets if necessary, and that hotel security, Capitol police, and the national guard would all be classified as “not targets if at all possible (aka unless they shoot at me”. Hotel employees and guests were not targets. “I am a citizen of the United States of America,” the letter states. “What my representatives do reflects on me. And I am no longer willing to permit a pedophile, rapist, and traitor to coat my hands with his crimes.” While the manifesto does not reference Trump by name, it alludes to grievances over a range of administration actions and recent events, including US strikes on drug smuggling boats in the eastern Pacific. Elsewhere, the presidents described the events of the night in an even tone, saying that he did not feel particularly alarmed as they unfolded. “I wasn’t worried,” Trump said in the interview when asked how worried he was about possible injuries after hearing the gunshots. “I understand life. We live in a crazy world.” Allen is believed to have traveled by train from California to Chicago and then on to Washington, where he checked himself in as a guest at the hotel days earlier where the gala dinner was held. Federal agents have interviewed Allen’s sister in Maryland, who told investigators her brother had legally bought several weapons from a California gun store and stored them at their parents’ home in Torrance without their knowledge, according to federal officials. #allen#trump#manifesto#assasination#washington 📱American Оbserver - Stay up to date on all important events 🇺🇸