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

Резултати

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

Пребарај: #greenland

当前筛选 #greenland清除筛选
International Geographic

@internationalgeographic · Post #5476 · 06.03.2025 г., 18:48

#Greenland🇬🇱 Eternal ice 🧊 Would you like to visit here? About 80% of the territory of Greenland is covered with an ice shield, which is the second largest in the world after Antarctica. The ice in some places reaches a thickness of up to 3 km. Greenland cuisine is based on the gifts of nature: fish, seafood, venison and dishes from marine mammals. For example, "Suasat" - sewen soup - is considered a traditional dish.

Hashtags

MAJOR

@major_auto_official · Post #4052 · 14.01.2026 г., 11:06

Отвлечемся на секунду от новостей автопрома и поговорим чуть о том, что в мире нет стабильности. Суматошный нестабильный эксцентричный президент США хочет заграбастать Гренландию. В одном из своих интервью он сказал, что армия Гренландии состоит из двух собачьих упряжек. Гордые жители создали шедевральный ии-шный ролик (точно пару дней потратили) в котором продемонстрировали свои военные возможности. У них есть собаки, моржи и пингвины (почему-то в форме образца СССР). Что мы вообще думаем об этой ситуации. Заберет или не заберет? Заберет - 👎 Не заберет - 👍 Вообще это какая то дичь - 🥴 Ролик огонь - ❤️ #greenland

Hashtags

Crypto Pump Club 📈

@cryptoclubpump · Post #1950 · 22.01.2026 г., 09:07

#GREENLAND RESULT ————————— PEAK: 1,109% If you think that was a great move, you haven't seen what we have planned for our next launch... After giving it to you guys, we pushed #GREENLAND over 1,100% in a matter of less than an hour, destroying our target and guaranteeing the biggest profits for our members. Trump is about to move the global economy again, and we're about to have the biggest 100x opportunity we've had in years. We're just getting started Stay tuned.

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #1520 · 04.08.2025 г., 12:14

👣 The iceberg's breath in northeast Greenland. Silence and icy expanses where every breath feels like nature itself. 📏 📏 📏 📏 📏 📏 📏 📏 #Greenland | @voyage

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #1448 · 12.06.2025 г., 12:14

👣 The iceberg's breath in northeast Greenland. Silence and icy expanses where every breath feels like nature itself. 📏 📏 📏 📏 📏 📏 📏 📏 #Greenland🇬🇱@voyage

Hashtags

Crypto Pump Club

@crypto_bitcoin_pumps_signal · Post #1417 · 22.01.2026 г., 09:10

#GREENLAND RESULT ————————— PEAK: 1,109% If you think that was a great move, you haven't seen what we have planned for our next launch... After giving it to you guys, we pushed #GREENLAND over 1,100% destroying our target and guaranteeing the biggest profits for our members. Trump is about to move the global economy again, and we're about to have the biggest 100x opportunity we've had in years. We're just getting started Stay tuned.

Hashtags

Voyage.Travel.Tourism

@VOYAGE · Post #1376 · 01.04.2025 г., 12:14

👣 The iceberg's breath in northeast Greenland. Silence and icy expanses where every breath feels like nature itself. 📏 📏 📏 📏 📏 📏 📏 📏 #Greenland🇬🇱@voyage

Hashtags

Trump's Ear

@trumpsear_tg · Post #2053 · 26.01.2026 г., 14:03

The United States abandoned the idea of seizing Greenland due to the threat of impeachment to Trump, - Reuters #Trump#Greenland 👂More on Trump's Ear ⚠️

Trump's Ear

@trumpsear_tg · Post #2049 · 23.01.2026 г., 20:59

The world would be a “better, more secure place” if America took over Greenland, Nigel Farage said at Davos, while insisting that he still believed in the sovereignty of nation states. During a panel at the World Economic Forum’s “America House” in the Swiss ski resort on Wednesday, the Reform UK leader said he had “no doubt” that the world would be safer if a “strong America” was in Greenland “because of the geopolitics of the high north, because of the retreating ice caps and because of the continued expansionism of Russian icebreakers, of Chinese investmen #Trump#Greenland 👂More on Trump's Ear ⚠️

Trump's Ear

@trumpsear_tg · Post #2005 · 14.01.2026 г., 17:59

The United States needs Greenland for national security reasons, Trump said. According to the US president, the island is important for the creation of the Golden dome system. And NATO is supposed to pave the way for America to get Greenland. #Trump#Greenland 👂More on Trump's Ear ⚠️

123•••78
ПретходнаСтраница 1 од 8Следна