Заметка начинающим, которые часто сталкиваются с подобной непоняткой.
Ситуация следующая, есть список файлов:
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
🚀 What an incredible start to Token2049!
The energy at the #CoinEx booth has been electric, with non-stop engagement from our global community.
A massive thank you to everyone who joined the queues for our exclusive merch, participated in vibrant discussions, and shared their insights on the future of crypto.
The excitement is just getting started. If you missed the Day 1 action, there's still time to connect.
Find us at our booth tomorrow!
⚡️ Transform your crypto experience with CoinEx, just like Wukong's 72 transformations. Get started today!
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
⚡️ Defy the odds like Wukong in battle. On CoinEx, every trade is a step toward your next big victory!
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
✔️ Master the art of trading, just like Wukong mastered his powers. Start with CoinEx today and become a crypto legend
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
✔️ Forge your own crypto legend with CoinEx, just like Wukong in his journey. Start trading today!
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
💥 Every trade is a step closer to victory! CoinEx is your battlefield—are you ready to conquer?
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
👍Like Wukong battling epic bosses, conquer your crypto journey with CoinEx. Sign up now and get ready to take on the world of digital assets!
➡️ Register CoinEx: https://www.coinex.com/register?refer_code=webgh
#Wukong#CoinEx
🔥 CoinEx continues to deliver on its promise! 🔥
💵$CET's 1st Monthly Repurchase & Burn 🔥 of 2026 is complete:
🔥🔥🔥🔥🔥🔥🔥🔥
🪙 Repurchased & Burned $CET: 13.4 M $CET
💰 Remaining $CET: 2.53 B $CET (25.3%~)
🔥🔥🔥🔥🔥🔥🔥🔥
In line with our commitment, we continue daily #CET repurchases & monthly token burns to maintain the #CoinEx deflationary mechanism.🌐
🖐 Find the details HERE
🎯 Why Hold $CET?
$CET isn’t just a token — it’s your key to the CoinEx ecosystem!
✅ Trading fee discounts
✅ VIP privileges & exclusive promos
✅ Daily interest rate discount in Margin borrow
✅ Daily buybacks & monthly burns
✅ Referral ratio upgraded, with up to 40% rewards
✅ Exclusive promotional privileges:
✅ CET Staking
✅ CoinEx Mining
As CoinEx grows, so does CET’s utility and value.
Find CoinEx:
🌐Web
❌𝕏
✉️Telegram
✈Announcement
🛜Discord
🔥 CoinEx continues to deliver on its promise! 🔥
💵$CET's 11th Monthly Repurchase & Burn 🔥 of 2025 is complete:
🔥🔥🔥🔥🔥🔥🔥🔥
🪙 Repurchased & Burned $CET: 16.9 M $CET
💰 Remaining $CET: 2.56 B $CET (25.6%~)
🔥🔥🔥🔥🔥🔥🔥🔥
In line with our commitment, we continue daily #CET repurchases & monthly token burns to maintain the #CoinEx deflationary mechanism.🌐
🖐 Find the details HERE
🎯 Why Hold $CET?
$CET isn’t just a token — it’s your key to the CoinEx ecosystem!
✅ Trading fee discounts
✅ VIP privileges & exclusive promos
✅ Daily interest rate discount in Margin borrow
✅ Daily buybacks & monthly burns
✅ Referral ratio upgraded, with up to 40% rewards
✅ Exclusive promotional privileges:
✅ CET Staking
✅ CoinEx Mining
As CoinEx grows, so does CET’s utility and value.
Find CoinEx:
🌐Web
❌𝕏
✉️Telegram
✈Announcement
🛜Discord
🔥 CoinEx continues to deliver on its promise! 🔥
💵$CET's 10th Monthly Repurchase & Burn 🔥 of 2025 is complete:
🔥🔥🔥🔥🔥🔥🔥🔥
🪙 Repurchased & Burned $CET: 16.9 M $CET
💰 Remaining $CET: 2.57 B $CET (25.7%~)
🔥🔥🔥🔥🔥🔥🔥🔥
In line with our commitment, we continue daily #CET repurchases & monthly token burns to maintain the #CoinEx deflationary mechanism.🌐
🖐 Find the details HERE
🎯 Why Hold $CET?
$CET isn’t just a token — it’s your key to the CoinEx ecosystem!
✅ Trading fee discounts
✅ VIP privileges & exclusive promos
✅ Daily interest rate discount in Margin borrow
✅ Daily buybacks & monthly burns
✅ Referral ratio upgraded, with up to 40% rewards
✅ Exclusive promotional privileges:
✅ CET Staking
✅ CoinEx Mining
As CoinEx grows, so does CET’s utility and value.
Find CoinEx:
🌐Web
❌𝕏
✉️Telegram
✈Announcement
🛜Discord
🔥 CoinEx continues to deliver on its promise! 🔥
💵$CET's 8th Monthly Repurchase & Burn 🔥 of 2025 is complete:
🔥🔥🔥🔥🔥🔥🔥🔥
🪙 Repurchased & Burned $CET: 22.2 M $CET
💰 Remaining $CET: 2.61 B $CET (26.1%~)
🔥🔥🔥🔥🔥🔥🔥🔥
In line with our commitment, we continue daily #CET repurchases & monthly token burns to maintain the #CoinEx deflationary mechanism.🌐
🖐 Find the details HERE
🎯 Why Hold $CET?
$CET isn’t just a token — it’s your key to the CoinEx ecosystem!
✅ Trading fee discounts
✅ VIP privileges & exclusive promos
✅ Daily interest rate discount in Margin borrow
✅ Daily buybacks & monthly burns
✅ Referral ratio upgraded, with up to 40% rewards
✅ Exclusive promotional privileges:
✅ CET Staking
✅ CoinEx Mining
As CoinEx grows, so does CET’s utility and value.
Find CoinEx:
🌐Web
❌𝕏
✉️Telegram
✈Announcement
🛜Discord
🔥 CoinEx continues to deliver on its promise! 🔥
💵$CET's 7th Monthly Repurchase & Burn 🔥 of 2025 is complete:
🔥🔥🔥🔥🔥🔥🔥🔥
🪙 Repurchased & Burned $CET: 17.45 M $CET
💰 Remaining $CET: 2.632 B $CET (26.3%~)
🔥🔥🔥🔥🔥🔥🔥🔥
In line with our commitment, we continue daily #CET repurchases & monthly token burns to maintain the #CoinEx deflationary mechanism.🌐
🖐 Find the details HERE
🎯 Why Hold $CET?
$CET isn’t just a token — it’s your key to the CoinEx ecosystem!
✅ Trading fee discounts
✅ VIP privileges & exclusive promos
✅ Daily interest rate discount in Margin borrow
✅ Daily buybacks & monthly burns
✅ Referral ratio upgraded, with up to 40% rewards
✅ Exclusive promotional privileges:
✅ CET Staking
✅ CoinEx Mining
As CoinEx grows, so does CET’s utility and value.
Find CoinEx:
🌐Web
❌𝕏
✉️Telegram
✈Announcement
🛜Discord