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

Резултати

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

Пребарај: #paleontology

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

@interesting_planet_facts · Post #945 · 21.10.2025 г., 18:11

🌎 The mysterious "terror bird" Titanis walleri once roamed North America about 2 million years ago. Standing nearly 2.5 meters tall, it was a flightless predator with a massive hooked beak. Fossils show it preyed on small mammals, and its closest living relatives are modern seriemas of South America. ✨ #paleontology⚡#fossils⚡#birds 👉subscribe Interesting Planet 👉more Channels ​

Galgame分享频道

@xiaomenggalgame · Post #153 · 04.12.2025 г., 00:11

海底 ▎介绍 逝去的时光不断沉入无比深邃的海底。 有时,那一天的景象和气息会像气泡一样浮起又消失。 楢崎是一家心身医学诊所的精神科医生,他一直在研究人们遗忘的机制。 人们为什么会遗忘,有没有办法避免遗忘重要的事情? 当她深入探究一位病人的思想时,她到达了深不见底的海底。 幸子(Sachiko)是一名设计师,在东京有一间办公室,她仍然痴迷于创造。 她不顾同事的担忧,继续工作,结果精神失常,开始看到过去情人的幻象。 她追寻着爱人的踪迹,发现了一条又长又黑的隧道。 住在疗养院里的 Kiko 记不起自己是如何与从幼儿园开始就在一起的同性爱人分手的。 她遇到了一个与她的恋人相似的女人,并逐渐恢复了记忆。 当她不断打开记忆之门时,终于走进了一间冰冷寂静的房间。 三个人怀着各自的目的,徘徊在寻找过去的路上,他们最终会去哪里呢? 三个人的故事在日复一日中悄然进行,最终回到了同一个地方。 ▎获取 PC仓库 ▎标签 系统:#PC 类型:#galgame#NSWF#汉化#百合 出版:#Paleontology

Interesting Planet 🌍

@interesting_planet_facts · Post #430 · 26.07.2025 г., 18:22

🌎 Ice Age cave lions once roamed across Europe and Asia, hunting mammoths and bison in frigid steppe. Larger than today’s lions, these extinct predators are known from beautifully preserved cave paintings and even mummified cubs found in Siberian permafrost. ✨ #paleontology⚡#megafauna⚡#prehistory 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1219 · 13.01.2026 г., 18:11

🌎 The chambered nautilus, often called a “living fossil,” has survived nearly unchanged for over 500 million years. Its spiral shell and tentacled, squid-like body resemble fossils from the early Paleozoic era. Living nautiluses inhabit deep reefs in the Indo-Pacific and can have over 90 tentacles. ✨ #nautilus⚡#paleontology⚡#evolution 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #438 · 27.07.2025 г., 16:22

🌎 The Gomphothere, an ancient cousin of elephants, once roamed the Americas with shovel-shaped lower jaws. These extinct giants sported four tusks instead of two, thriving for millions of years before vanishing at the end of the last Ice Age. ✨ #paleontology⚡#megafauna⚡#extinction 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #486 · 02.08.2025 г., 16:22

🌎 Long before trees, Earth was covered in giant mushrooms called Prototaxites, some reaching up to 8 meters tall. These towering fungi dominated ancient landscapes 420 million years ago, before forests appeared. ✨ #paleontology⚡#fungi⚡#prehistory 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #480 · 01.08.2025 г., 16:22

🌎 The pikaia, a tiny worm-like creature from 500 million years ago, may be one of our earliest known ancestors. Its flexible, cord-like structure helped pave the way for the backbone found in all vertebrates today. ✨ #evolution⚡#paleontology⚡#ancestry 👉subscribe Interesting Planet

Interesting Planet 🌍

@interesting_planet_facts · Post #1176 · 30.12.2025 г., 18:11

🌎 Australian megafauna like Diprotodon, the largest marsupial ever, disappeared about 46,000 years ago. These giant wombat relatives weighed up to 2,750 kilograms. The cause of their extinction is debated—some studies suggest climate shifts, while others blame human hunting. Diprotodon fossils have been found at over 100 sites across Australia. ✨ #extinctanimals⚡#megafauna⚡#paleontology 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #1090 · 01.12.2025 г., 18:11

🌎 The mysterious extinction of the “Siberian unicorn,” or Elasmotherium sibiricum, puzzles paleontologists. This massive Ice Age mammal, related to modern rhinos, had a large forehead horn and grazed Eurasian steppes. DNA studies show it survived until about 39,000 years ago—much later than once thought. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #877 · 08.10.2025 г., 15:11

🌎 The woolly rhinoceros, Coelodonta antiquitatis, roamed Ice Age Eurasia with a thick fur coat and massive horn. Fossils found in Siberian permafrost show it survived extreme cold; its extinction about 14,000 years ago is linked to climate warming and human hunting. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #812 · 25.09.2025 г., 15:11

🌎 The giant short-faced bear, Arctodus simus, roamed North America during the last Ice Age. Standing up to 1.5 meters at the shoulder, it was one of the largest terrestrial mammalian carnivores ever, yet paleontologists debate if it was mainly a predator or a scavenger. Fossils suggest it vanished around 11,000 years ago, along with much other megafauna. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #715 · 09.09.2025 г., 03:22

🌎 The Siberian unicorn, or Elasmotherium, was a massive prehistoric rhinoceros with a single huge horn on its forehead. Fossils show it roamed Eurasia until about 39,000 years ago, much later than once believed. ✨ #extinctanimals⚡#paleontology⚡#iceage 👉subscribe Interesting Planet ​

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