Заметка начинающим, которые часто сталкиваются с подобной непоняткой.
Ситуация следующая, есть список файлов:
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
🇺🇸US soldier arrested for betting on Maduro’s capture — won over $400 000💰
A U.S. Army Special Forces master sergeant, Gannon Ken Van Dyke, has been arrested and charged after allegedly using classified military information to place bets on an online prediction market and win more than $400 000 based on the outcome of a covert operation that captured Venezuelan president Nicolás Maduro.
Van Dyke, who was involved in Operation Absolute Resolve — the U.S. military mission that led to Maduro’s capture on January 3 — reportedly placed about 13 bets on the platform Polymarket, wagering that Maduro would be removed from power. Prosecutors say he used nonpublic knowledge of the operation to make strategic trades that paid off once the raid became public.
Federal authorities have indicted him on multiple counts, including unlawful use of confidential information for personal gain, commodities fraud, wire fraud, and illegal use of classified data. Van Dyke allegedly tried to conceal his identity and the proceeds by using foreign cryptocurrency accounts and requesting deletion of his Polymarket account after the operation was announced.
Officials and lawmakers have condemned the case as a serious breach of trust and a form of insider trading in prediction markets, highlighting concerns about the misuse of secret information for profit.
#Military#DOJ#InsiderTrading
👂More on Trump's Ear ⚠️
Quiver Quantitative | 𝕏
You can track Cantor Fitzgerald's stock portfolio on Quiver:
https://www.quiverquant.com/institutions/CANTOR%20FITZGERALD,%20L.%20P./
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: Cantor Fitzgerald, run by the children of Commerce Secretary Howard Lutnick, just filed a portfolio update.
They bought up huge amounts of Bitcoin, Trump Media stock, and stock in the Chinese company Alibaba.
Full portfolio below.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
You can track Jane Street's stock portfolio on Quiver:
https://www.quiverquant.com/institutions/JANE%20STREET%20GROUP,%20LLC/
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
JUST IN: Jane Street just filed a holdings update.
They added approximately $1B of Bitcoin to their portfolio.
It is now their largest holding.
Full portfolio below.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
You can track Michael Burry's portfolio here:
https://www.quiverquant.com/institutions/Scion%20Asset%20Management,%20LLC/
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: Michael Burry, of "The Big Short" fame, just filed a portfolio update.
He added:
- UnitedHealth, $UNH
- Lululemon, $LULU
- Bruker, $BRKR
- Regeneron, $REGN
- MercadoLibre, $MELI
Track his full portfolio on Quiver.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
We received this data just 15 minutes ago.
Since then:
$UNH +7%
$NUE +6%
$LEN +4%
$DHI +3%
$ALL +0.5% https://twitter.com/QuiverQuant/status/1956086663156830469
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
We expect to have an update on Warren Buffet's portfolio in the next hour.
This might reveal the identify of the mystery stock that he has been buying up.
Turn on post notifications!
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading
Quiver Quantitative | 𝕏
BREAKING: We just received new data on Senator Dave McCormick's portfolio.
He has up to $5M in Bitcoin, $IBIT.
He also has to $1M in Ethereum, $ETHW.
McCormick sits on the Senate Subcommittee on Digital Assets.
Full portfolio up on Quiver.
~
₿izFeed#⃣:#stockmarketdata#stockmarketnews#insidertrading