Заметка начинающим, которые часто сталкиваются с подобной непоняткой.
Ситуация следующая, есть список файлов:
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
🆕 TokenPocket Chrome Extension's Latest (1.2.3) Version has enabled Nostr Protocol by default! #Nostr
👉https://extension.tokenpocket.pro/#/
✅With no complex setting steps, all the TokenPocket users can get their own Nostr address easily!
🎯Your Points Matter! TokenPocket will keep working on listening to communities' voices and optimizing users' experience. #TokenPocket#nostr
How to enable Nostr Protocol on TokenPocket Mobile wallet?
Guide 👉https://help.tokenpocket.pro/en/wallet-operation/protocol/nostr
【Details】https://twitter.com/TokenPocket_TP/status/1745755553039802879
【Powered By】Crypto Box
🔵Enjoy Nostr Protocol on TokenPocket_TP.
TokenPocket now supports #Nostr Protocol on Mobile Wallet and Chrome Extension Wallet. You can easily enable your #Nostr address on #TokenPocket!
Guide👇
https://tokenpocket-gm.medium.com/enjoy-nostr-protocol-on-tokenpocket-b53044dd10f0
【Details】https://twitter.com/TokenPocket_TP/status/1733450921391358056
【Powered By】Crypto Box
#Nostr Protocol is now available on TokenPocket_TP!
🔥TokenPocket now provides the Nostr support for #Bitcoin, dogecoin network, and all the EVM-compatible networks!
How to enable Nostr in your TokenPocket wallet?
🔵Android: Tap “Me” - “Experience” - Enable Nostr. You can get your Nostr address by tapping “Details” on the Assets Page.
🔵iOS: Tap “Me” - “Setting” - Turn on “Nostr”. You can get your Nostr assets by tapping “Details” on the Assets page.
#taproot#bitcoin#Nostr
【Details】https://twitter.com/TokenPocket_TP/status/1724712691523100844
【Powered By】Crypto Box
🌟Nostr Protocol is Live On TokenPocket!
>Both on Mobile Wallet and Chrome Extension.
And Nostr Protocol is available for all the EVM-compatible networks, #Bitcoin, and also #Dogecoin on TokenPocket!
🔥Nostr is a simple, open protocol for a global, decentralized, and censorship-resistant social networking system.
📝Here is the tutorial to guide you on how to enable/support #Nostr on your TokenPocket wallet.
👉https://help.tokenpocket.pro/en/wallet-operation/protocol/nostr
🔥#Nostr Protocol is Live On TokenPocket_TP!
>Both on Mobile Wallet and Chrome Extension.
🔥Nostr is a simple, open protocol for a global, decentralized, and censorship-resistant social networking system.
Here is the tutorial to guide you on how to enable/support #Nostr on your TokenPocket wallet.
👉https://help.tokenpocket.pro/en/wallet-operation/protocol/nostr
📣All in TokenPocket! #Nostr#EnableNostr#Bitcoin
👉https://www.tokenpocket.pro/
👉https://extension.tokenpocket.pro/ NoScription
【Details】https://twitter.com/TokenPocket_TP/status/1741998782320136275
【Powered By】Crypto Box
#Bitcoin Eco is on fire!!🔥🔥🔥
TokenPocket Mobile Wallet now provides a super easy-to-use experience for most #Nostr-based DApps. Recently, we also noticed that there is a new product live on #Nostr Protocol. NostrAssets
📣You can discover Nostr Assets on NostrAssets with #TokenPocket and access the new era of #Bitcoin Eco.
> Enter "NostrAssets" on your Discover page then you can find it! ✅✅
Just the beginning!
💥 Let's work together and bring more highlights to #Bitcoin! #Taproot
❓How to enable #Nostr on your TokenPocket?
Tutorial👉https://help.tokenpocket.pro/en/wallet-operation/protocol/nostr
【Details】https://twitter.com/TokenPocket_TP/status/1719933875059855422
【Powered By】Crypto Box
#AMA TokenPocket × NostrSwap
⏰Jun 29th, 1 PM UTC
🪑 Venue: https://t.me/tokenPocket_en
✅Comment your Qs about NostrSwap, #BRC20 and #Nostron Twitter before AMA.
✅Join Telegram and enjoy the live AMA
🎁100 USDT to 5 best Twitter Qs & 5 best Live Qs
Zapstore
Permissionless and social app store built on the #nostr protocol
For #Android#Linux and #Mac
https://zapstore.dev
Download
https://zapstore.dev/download/
Sources
https://github.com/zapstore
Secure by default
Everything you install comes from trusted sources and is cryptographically verified. Not satisfied with the default? Choose your own curators, or mix and match! Censorship has no place in our world.
Relevant to you
Supercharged by the nostr open protocol, recommendations come right from your social connections — or use it in totally private way. With our growing catalog, you will never run out of great apps.
Support your devs
Connect with your favorite developers: send them direct feedback, request features and support them through micropayments, all without any middlemen.
#apk#store