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

Резултати

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

Пребарај: #nuclearambitions

当前筛选 #nuclearambitions清除筛选
Crypto M - Crypto News

@CryptoM · Post #65275 · 12.04.2026 г., 13:14

🚀 Trump Reaffirms Iran's Nuclear Ambitions as a Red Line U.S. President Donald Trump reiterated his stance on Iran's nuclear ambitions, emphasizing it as a red line. According to BlockBeats, Trump stated that he received a comprehensive briefing from Vice President Vance, Special Envoy Whitcoff, and Kushner regarding the meeting in Islamabad. The discussions with Iran extended from early morning until late at night, lasting nearly 20 hours. Trump expressed that while he could elaborate on the meeting's details and the numerous achievements, the critical issue remains Iran's unwillingness to abandon its nuclear ambitions. He noted that the consensus reached in many areas was preferable to continuing military actions until the end. However, he stressed that these agreements are insignificant compared to the risk of nuclear power being in the hands of unpredictable individuals. Trump reiterated his long-standing position that Iran will never possess nuclear weapons, a stance he has maintained for many years. #Trump#Iran#NuclearAmbitions#RedLine#USPolitics#InternationalRelations#Diplomacy#NuclearWeapons#MiddleEast

Crypto M - Crypto News

@CryptoM · Post #65277 · 12.04.2026 г., 13:24

🚀 Polymarket Predicts WTI Crude Oil Price Surge by 2026 The probability of WTI crude oil reaching $110 by April 2026 has significantly increased on Polymarket, now standing at 67%, with a 13% rise in the last hour and a 20% increase over 24 hours. According to Odaily, the total trading volume for this event contract has surpassed $24 million. The contract stipulates that if the highest price of any one-minute candlestick for WTI crude oil futures during April 2026 equals or exceeds the listed price, the market will be deemed a 'yes'; otherwise, it will be a 'no'. Previously, the March WTI crude oil price prediction contract required the official settlement price of the active month contract on any trading day at the Chicago Mercantile Exchange to meet or exceed the listed price by the last trading day of March 2026 for a 'yes' outcome. U.S. President Donald Trump announced today that the U.S. Navy, the world's most powerful naval force, will begin blocking any vessels attempting to enter or exit the Strait of Hormuz. He also ordered the Navy to search and intercept any ships that have paid transit fees to Iran in international waters. Those who have paid such fees will not be allowed safe passage on the high seas, and efforts will begin to destroy Iranian mines in the strait. Trump warned that any Iranian who fires upon peaceful vessels will face severe consequences. He stated that Iran knows how to end the war that has devastated their country, noting the loss of their navy, air force, and defense systems, as well as the deaths of leaders including Khamenei, all due to their nuclear ambitions. The blockade is set to begin with other countries joining in, ensuring Iran does not profit from illegal extortion. Iran seeks money and, more importantly, nuclear weapons. #WTICrudeOil#OilPricePrediction#Polymarket#TradingVolume#April2026#USNavy#StraitOfHormuz#Iran#Trump#NuclearAmbitions#InternationalSecurity