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

Резултати

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

Пребарај: #timezones

当前筛选 #timezones清除筛选
Amazing Geography 🌍

@amazingeo · Post #454 · 14.11.2025 г., 20:31

🌍 The island nation of Kiribati is so spread out that it once straddled the International Date Line. In 1995, it shifted the line eastward, so the entire country could share the same date. ✨ #timezones⚡#Pacific⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #685 · 08.04.2026 г., 20:31

🌍 Time zones are not always set by longitude—some countries, like China, use one time zone nationwide despite spanning five natural zones, affecting daily life from sunrise to sunset across vast distances. ✨ #timezones⚡#clocks⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #186 · 06.09.2025 г., 09:12

🌍 Some time zones offset by just 15 or 30 minutes exist, like India’s UTC+5:30 and Newfoundland’s UTC−3:30. These unusual divisions reflect local choices instead of sticking to whole hours. ✨ #timezones⚡#clocks⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40446 · 31.12.2025 г., 10:04

Kiribati starts the New Year exactly now!!! At midnight (UTC+14). When it’s midnight there, it’s still 10 AM in London, 11 AM in Brussels (Europe, Belgium), and 1 PM in Moscow on December 31. Europe welcomes the New Year 12–14 hours after Kiribati. ⏰🌏🎉 [Read more1] [Read more2] When does your new year start? This post also counts as the place to send your New Years greetings/Wishes! We wish you all a fun, fulfilling, healthy and happy New Year! @googlefactss #NewYear#Kiribati#TimeZones#Facts

Amazing Geography 🌍

@amazingeo · Post #341 · 06.10.2025 г., 20:31

🌍 Some Antarctic research stations use New Zealand’s time zone, while others choose the time of their home country. This means clocks at the South Pole can show different times—sometimes up to 12 hours apart. ✨ #timezones⚡#antarctica⚡#clocks⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #66 · 17.08.2025 г., 16:12

🌍 The border between Norway and Russia runs along a tiny river, but despite being so far north, the local time can differ by two hours due to the countries choosing different time zones. ✨ #timezones⚡#borders⚡#Scandinavia⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #523 · 19.12.2025 г., 12:31

🌍 Nepal is one of the few countries that advances its clocks by 45 minutes from standard time, using a unique offset of UTC+5:45 to better match local solar time. ✨ #timezones⚡#Nepal⚡#clocks⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #221 · 12.09.2025 г., 03:12

🌍 Daylight saving time isn't used worldwide; many countries near the Equator never change their clocks because daylight hours barely vary throughout the year. ✨ #timezones⚡#daylight⚡#equator⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #74 · 19.08.2025 г., 00:12

🌍 On January 1 each year, the first sunrise on Earth is usually seen in the Pacific island nation of Tonga or its neighbor, depending on the position of the International Date Line. ✨ #timezones⚡#sunrise⚡#Pacific⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

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