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

Резултати

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

Пребарај: #animals

当前筛选 #animals清除筛选
Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40547 · 16.01.2026 г., 23:01

The scientific name for "coyote" is canis latrans, which literally means "barking dog", a fitting description for its wide variety of yips, howls, and barks used for communication, with the name coming from the Aztec word for the animal. @googlefactss#animals

Hashtags

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40082 · 13.11.2025 г., 20:50

Female elephants stay with the same herd their entire lives. Males only remain with the herd until they are 12 to 15 years old. The Male elephants then either join a "bachelor" herd or they live alone only rejoining the females during mating season. @googlefactss#animals

Hashtags

EKOLOG.UZ| ENG

@ekologuzenglish · Post #11860 · 09.03.2026 г., 15:02

#Animals Animals help each other too, and sometimes they do it more sincerely than humans. In nature, there are many amazing examples of cooperation: birds warn their flock about danger, dolphins support injured companions, elephants protect their calves, and some animals share food with those who are weak. This invisible bond of support and care is part of the harmony of nature. In the wild, survival often depends on cooperation and strong social connections. By observing animals, we learn a simple truth: the world is sustained not only by strength, but also by compassion, trust, and mutual help. 🐾🌿☘️Read the latest environmental news on the @ekologuz page. Follow us and send your suggestions and wishes via @eklguz_bot Instagram | Facebook | Twitter | Sayt | Youtube.

Hashtags

Daily Channels

@dailychannels · Post #6553 · 19.12.2025 г., 01:00

Channel: Dangerous Earth Members: ~5.44K 💢 Username: @dangerousground Description: Craters, volcanoes, avalanches, brutal animal scenes, deadly attacks by predators and many other strange displays of the forces of nature and its inhabitants. Buy ads: https://telega.io/c/dangerousground 🏷 Tags: #animals https://telegramchannels.me/channels/dangerousground

Hashtags

123•••5•••10•••15•••20•••25•••30•••35•••40•••45•••50•••55•••60•••6566
ПретходнаСтраница 1 од 66Следна