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

Резултати

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

Пребарај: #permafrost

当前筛选 #permafrost清除筛选
Interesting Planet 🌍

@interesting_planet_facts · Post #825 · 27.09.2025 г., 22:11

🌎 In the Norwegian Arctic, the town of Longyearbyen bans dying at home, as bodies can't decompose in permafrost. Residents who are terminally ill must travel to the mainland. This small settlement is also the northernmost town with over 1,000 people. ✨ #arctic⚡#settlements⚡#permafrost 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #580 · 18.08.2025 г., 00:22

🌎 The Siberian permafrost preserves ice age seeds for tens of thousands of years. Scientists have revived ancient plants, like Silene stenophylla, from seeds frozen over 30,000 years ago—proving some life can return after millennia in the deep freeze. ✨ #permafrost⚡#botany⚡#revival 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #729 · 11.09.2025 г., 16:22

🌎 Norilsk, Russia, is a city built above the Arctic Circle and is so remote that it’s closed to most foreigners. Founded in 1935 for nickel mining, it endures harsh winters with temperatures as low as −55°C. Norilsk is one of the largest cities in continuous permafrost and has no rail or road connection to the rest of Russia. ✨ #Norilsk⚡#Arctic⚡#permafrost 👉subscribe Interesting Planet ​

Amazing Geography 🌍

@amazingeo · Post #206 · 09.09.2025 г., 16:12

🌍 Some tundra soils contain buried ice wedges that can be thousands of years old. When permafrost thaws, these ancient ice wedges melt, creating strange sinkholes called "thermokarst." ✨ #permafrost⚡#tundra⚡#landscape⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #547 · 31.12.2025 г., 12:31

🌍 In tundra landscapes, some mosses and lichens can survive temperatures below –50°C and continue to photosynthesize under snow, making them some of the Earth’s hardiest plants. ✨ #tundra⚡#permafrost⚡#adaptation⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #668 · 21.03.2026 г., 20:31

🌍 In the far north, frozen permafrost soils hide ancient bacteria and seeds that can survive for thousands of years—emerging only when the tundra thaws after centuries of deep freeze. ✨ #permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #626 · 11.02.2026 г., 20:31

🌍 In the Siberian tundra, permafrost preserves massive underground "ice wedges" that crack open each winter and refill with meltwater every spring, leaving polygon patterns visible from above. ✨ #permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #439 · 07.11.2025 г., 12:31

🌍 Some tundra ponds form when summer sun thaws just the surface of permafrost, creating seasonal lakes that vanish each year. These ponds support bursts of life in otherwise frozen landscapes. ✨ #tundra⚡#permafrost⚡#arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #326 · 03.10.2025 г., 12:31

🌍 In the Arctic tundra, some permafrost layers are over 1,500 meters thick—deeper than most skyscrapers are tall. This frozen ground stores ancient DNA from plants and animals tens of thousands of years old. ✨ #permafrost⚡#tundra⚡#arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #245 · 16.09.2025 г., 03:12

🌍 In some Arctic tundra areas, ancient animal tracks remain frozen in permafrost for thousands of years. When the ground thaws, these footprints reappear, revealing hidden stories of past wildlife. ✨ #permafrost⚡#tundra⚡#Arctic⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1120 · 11.12.2025 г., 18:11

🌎 Every summer in Siberia, mysterious craters known as "Yamal holes" appear in the Arctic tundra. These giant pits, sometimes 20 meters wide, form when underground methane gas builds pressure and violently explodes through permafrost. Scientists have identified at least 17 such craters since 2014, linking them to warming temperatures and melting ice. ✨ #permafrost⚡#methane⚡#explosions 👉subscribe Interesting Planet 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #708 · 06.05.2026 г., 20:31

🌍 In parts of Siberia, thawing permafrost can trigger sudden ground collapses called “thermokarst.” These sinks reshape the tundra and can swallow trees or create lakes almost overnight. ✨ #permafrost⚡#tundra⚡#landforms⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

12
ПретходнаСтраница 1 од 2Следна