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

Резултати

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

Пребарај: #gemifaucet

当前筛选 #gemifaucet清除筛选
Gemi Faucet News

@gemifaucet · Post #1577 · 05.05.2026 г., 06:06

🎯Big Opportunity: Turn 2 TON into 100 TON!💰 Get ready to test your luck with our latest Lottery Draw on Gemifaucet! 🎟Ticket Price: Only 2 TON 🏆Winning Prize: Up to 100 TON ⏳Draw Time: Every 3 Days Here’s your chance to multiply your TON in a simple and exciting way. Just grab your ticket, sit back, and wait for the draw — one lucky winner will walk away with a massive reward! 🔥 Don’t miss out — the sooner you enter, the bigger the prize pool grows. 🚀Buy your ticket now and secure your chance to win big! #Gemifaucet#Lottery#WinTON#CryptoOpportunity Buy Now

Gemi Faucet News

@gemifaucet · Post #1573 · 04.05.2026 г., 18:47

🎉Exciting Update: Lottery Feature is Now Live on Gemifaucet!🎉 We’re thrilled to introduce a brand-new way to win big on Gemifaucet — our Lottery System is officially launched! 🎟How it works: * Purchase your lottery tickets directly داخل the app * Each ticket gives you a chance to win * One lucky winner takes home the entire prize pool💰 🔥 The more participants, the bigger the rewards — so don’t miss your chance to be part of it! This feature is designed to make your experience more engaging, rewarding, and fun. Whether you're a regular user or just getting started, now is the perfect time to try your luck. 🚀Start buying your tickets today and aim for the jackpot! Stay tuned for more updates and features coming soon. #Gemifaucet#LotteryLaunch#WinBig#CryptoRewards

Gemi Faucet News

@gemifaucet · Post #771 · 10.02.2026 г., 07:09

💥 OFFICIAL PARTNERSHIP ANNOUNCEMENT 💥 We’re pleased to announce an official partnership between Gemifaucet and AdsGram, focused on improving monetization quality and user experience across our platform. 🚀 About Gemifaucet Gemifaucet is a Telegram mini app where users receive rewards by interacting with tasks and ads in a simple, transparent, and user-friendly environment. 📊 About AdsGram AdsGram is a leading Telegram Native Ads platform trusted by top Telegram apps and communities. It provides seamless, non-intrusive ad solutions with strong performance, advanced analytics, and a proven monetization ecosystem. 🤝 Why this partnership matters By this official partnership formalizes our collaboration and strengthens our monetization infrastructure. 👉 Gemifaucet: @gemifaucet_bot 👉 AdsGram: @adsgram_ai Thank you for your continued support — more updates coming soon! 🚀 #OfficialPartnership#Gemifaucet#AdsGram#TelegramMiniApp#Announcement