Заметка начинающим, которые часто сталкиваются с подобной непоняткой.
Ситуация следующая, есть список файлов:
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
Hey, you can check your $ZRO Token Airdrop eligibility on TokenPocket!
📱Open TokenPocket > Switch to the Discover page > You can see the DApp on the Airdrop Zone!
💻You can get the checking page on TokenPocket's DApp Store!
👉https://tokenpocket.pro/en/dappstore
Good luck! 💙#LayerZero
Layer Zero AirDrop Starts NOW!
All active participants will receive a guaranteed drop of $ZRO tokens.
Airdrop : https://linktr.ee/labslayerzero
A total of 12.000.000 $ZRO coins have been allocated, time is limited!
#layerzero#airdrop#tokens#coin
📋The sensational #LayerZero (ZRO) is trading at $ 3.05 and the current circulation of unlocked coins is only $ 770 million, the total capitalization is also small - $ 3 billion, which is 2-3 times less than Aptos or SUI. #zkSync (ZK) has a similar picture, the total capitalization is even more than ZRO by 900 million.
🧐It looks very modest, I think few people predicted this. Looking at this picture, you start to worry about the rest of the altos with large capitalization. And looking at the small ones, you also think about it. After this, is it possible to believe in a further correction of Chia (XCH)?
🥸Both projects are technologically advanced, but in different aspects. zkSync focuses on scaling and efficiency within a single blockchain (Ethereum) using advanced cryptographic techniques. LayerZero is aimed at improving the interaction between different blockchains, which is also an important task for the entire industry.
😎I think for #ZRO and #ZK you need to allocate a place in your portfolio, lay a theoretical descent lower by 30-50% and start buying a ladder from the current level, of course we are talking about spot. That is, to allow a speculative decrease in ZRO to $ 2.1 and ZK to $ 0.13 due to a speculative decrease and liquidation of longs on futures. But you need to understand that the current price is already very attractive, you need to partially buy now.
0⃣#ZRO + #Tether = 🚀🚀🚀
Tether recently invested in #LayerZero, and you know they don't drop cash without deep due diligence. 🕵️♂️ The fundamentals are rock solid.
This rally is just the beginning. 🌤 I’m stacking as much $ZRO as possible. targeting 2x - 5x gains! 💸
Get in or get left behind.👋
#DeFi#BullRun $ZRO #ZROUSDT
https://x.com/CryptoBull_360/status/2021403228970315928?s=20
Bitcoin: Panic Buying Amid Market Shakeup
Panic reactions in the market are evident as Bitcoin fluctuates. Key developments in the TON ecosystem include:
- TVM Ventures launching a $100M fund for TON growth 🔗
- Updates from TON Core for Dec 2024 - Jan 2025 🔗
- Steve Yun discusses DeFi’s future in Telegram on CNBC 🔗
- First mid-core web3 game launched on TON 🔗
- Support program for Mini Apps initiated 🔗
- Innovations from Notcoin team highlighted 🔗
- LayerZero’s new USDT bridge enhances TON’s cross-chain capabilities 🔗
- Key investments in DeFi and SocialFi detailed by TVM Ventures 🔗
- TON’s ecosystem expands beyond major project monopolies 🔗
- TRM Labs introduces a comprehensive blockchain analysis tool for TON 🔗
- The domain believers.ton is permanently lost 🔗
#Bitcoin#DeFi#TON#Crypto#Web3#Investment#LayerZero#Blockchain#MiniApps#PanicBuying#TVMVentures#Notcoin#TRMLabs
Multiple Fundraising Rounds Announced
Several companies secured funding recently:
- OpenCopilot raised $1.52M for AI customer support.
- Archive Intel secured $1.50M for AI-driven data archiving solutions.
- Serene obtained $1.14M using AI for customer insights and compliance.
- Sytrex raised $1.10M to aid financial institutions.
- Tire Swing acquired $500K focusing on cybersecurity.
In other news, the SEC sues Elon Musk over misleading shareholders during the Twitter acquisition, and Meta plans to lay off 3,600 employees for inefficiency. More updates on AI job creation and Bitcoin market analysis suggest significant changes ahead.
#Funding#AI#Crypto#SEC#ElonMusk#Meta#Bitcoin#CustomerSupport#DataArchiving#FinancialInstitutions#AIJobs#LayerZero#Serene#Sytrex#TireSwing#ArchiveIntel#OpenCopilot