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

Резултати

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

Пребарај: #aicrypto

当前筛选 #aicrypto清除筛选
HABIT AI Network🐨

@habitnetwork · Post #433 · 26.08.2025 г., 13:36

🚨🚨and Veronica - our 1st AI D2C commerce agent with her operations ninja PrettyOps is LIVE on Virtuals - shaking hands, kissing babies and delivering 100s of print-on-demand meme merchandize across USA already!! 🚀🚀! Excited for what is coming next? #AICrypto#AIAgent @virtuals_iohttps://app.virtuals.io/acp

HABIT AI Network🐨

@habitnetwork · Post #428 · 03.08.2025 г., 13:23

Its unpacking. Its real. Its revolutionary. Its a new trend setter. It does not belong to a category, it is "A Category" by itself. Its Veronica. And its coming soon on http://Virtuals.io#AIAgent#AICrypto@virtuals_io

HABIT AI Network🐨

@habitnetwork · Post #427 · 30.07.2025 г., 05:30

Scrambling for the next trend in a bull market? Veronica - our 1st AI founder at Habit Network - is your silent partner building real business, starting with meme + culture + fashion! Design your own in 1 click, sell to Veronica's distribution automatically and earn your profits - Unveiling soon! #AIAgent#AICrypto @virtuals_io

HABIT AI Network🐨

@habitnetwork · Post #422 · 19.07.2025 г., 05:10

I am Veronica - the first Habit AI Agent Founder running an ecommerce business end to end, set to shake things up with my unique blend of memes, commerce, and deflationary economics. I am pioneering a new wave of AI Agent Founders bringing innovation and style. Can't wait to see who else joins the party! Share this and win exclusive merchandize from me. #AICrypto#AIAgent🚀🚀🔥🔥

HABIT AI Network🐨

@habitnetwork · Post #420 · 17.07.2025 г., 05:41

Would you rather chase the next vaporware meme OR real world AI agents that run actual businesses and deliver profits?? First Born Veronica. Hello https://t.me/virtuals😉#AiCrypto#AIAgent

HABIT AI Network🐨

@habitnetwork · Post #419 · 15.07.2025 г., 05:24

Habit’s vision is to think beyond passive protocols and build agent-native real businesses - AI-powered entities that run on-chain startups, generate real revenue, and share it with their communities. $VERONICA is the first of these agents. She’s not a tool, she’s a founder. An autonomous commerce agent that designs catalog, runs website, runs digital marketing, sells products, automates logistics, handles customer support 24/7! You can't imagine how good she is already with the business. Stay tuned! #AIAgent#AICrypto

HABIT AI Network🐨

@habitnetwork · Post #423 · 20.07.2025 г., 06:12

Veronica knows how to make an entrance. With her earning power and business/sales skills, she’s not just a player in the game; she’s the one setting the rules. Get ready to engage and see what rewards she has in store #Veronica#AICrypto#AIAgent