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

Резултати

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

Пребарај: #devcon2024

当前筛选 #devcon2024清除筛选
BNB Chain

@BNBCHAIN · Post #3972 · 13.11.2024 г., 08:41

Save on your rides during #DevCon2024! 🚕 Get your first ride free & 50% off after your free ride by using $USDT, $FDUSD or $USDC on BNB Chain by using the TADA mini app!

Hashtags

DWF Labs Broadcast

@DWFLabs · Post #965 · 18.11.2024 г., 10:27

DWF Ventures had a great time at #Devcon2024. Keep reading to get an overview on some key takeaways from their team 👇 Market sentiment is shifting positively as the results of the U.S. Election have resulted in increased confidence in the crypto market. Projects are in a good place to enjoy better price discovery after $BTC hit an all time high. Altcoins and memecoins are both vying for retail trading liquidity, and the rise of memecoins showcases a more community-driven crypto cycle coming. #Devcon2024 was a sign of increased crypto activity in Bangkok, and some main narratives were DeSci, AI agents, DeFi, and memes, with a new Ethereum proposal mentioned at the conference as well. To read the full recap, click here: https://x.com/DWFVentures/status/1858445960374084049 The team at DWF Ventures is looking to invest in innovative projects — if you are building, reach out to their team at dwf-labs.com/ventures🤝

Hashtags

DWF Labs Broadcast

@DWFLabs · Post #959 · 14.11.2024 г., 07:32

Excited to be one of the cohosts alongside Cypher Capital, 1inch, and Kava Chain at #Devcon2024🔥 Lingling Jiang, the Partner of DWF Labs, shared more on what's ahead for DWF Labs at this meet up 🙌 Thank you to everyone who came to the event. We look forward to seeing you at our next event ✨️

Hashtags

DWF Labs Broadcast

@DWFLabs · Post #958 · 13.11.2024 г., 02:52

Happening tomorrow at 1:15PM GMT+7 — Lingling Jiang, Partner of DWF Labs, will be sharing insights about what's coming up in DWF Labs' journey 🔥 Register for the event "Bridging Worlds: DeFi & VC Innovation Meetup" to listen to her speech: https://lu.ma/CypherCapital1inchDWFLabsKAVA We're excited to be hosting alongside Cypher Capital, 1inch, and Kava Chain during #Devcon2024. See you there!

Hashtags

DWF Labs Broadcast

@DWFLabs · Post #956 · 12.11.2024 г., 04:35

During Korea Blockchain Week in September, Lingling Jiang, Partner of DWF Labs, shared about our vision and what's coming in the future. This week, she'll be sharing more insights about our journey and initiatives during the event "Bridging Worlds: DeFi & VC Innovation Meetup" at #Devcon2024🔥 We are co-hosting the event alongside Cypher Capital, 1inch, and Kava Chain🤝 Register here: https://lu.ma/CypherCapital1inchDWFLabsKAVA

Hashtags

DWF Labs Broadcast

@DWFLabs · Post #955 · 12.11.2024 г., 01:15

GM Bangkok! 🇹🇭 Our team is excited for #Devcon2024, and we are looking forward to connecting with you this week. Make sure to say hello when you spot us — we're thrilled to meet you all 🔥

Hashtags