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

Резултати

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

Пребарај: #december2022

当前筛选 #december2022清除筛选
The Open Platform

@topco · Post #27 · 04.01.2023 г., 09:04

DeFi: December headlines - Solana DeFi is down 98% from $10.17 Billion: the sharp decline has been majorly linked with the FTX demise as SBF, FTX’s former CEO, now termed the biggest fraudster in history, strongly backed Solana’s native token, SOL (source) - Uniswap overtakes Solana and becomes 16th top crypto: market data shows that Uniswap’s market cap stands at $3.875 billion. It is 5.36% higher than solana’s current market cap of $3.678 billion (source) - Solana DeFi exchange Raydium hacked for over $2 million (source) - 6 quadrillion tokens were hacked on DeFi protocol Ankr, which is speculated to be an inside job (source) - SushiSwap proposes 'immediate' action to support its treasury: SushiSwap is facing a significant deficit in its treasury that threatens its long-term operational viability, to address this, lead developer Jared Gray proposed setting Kanpai, a fee-diversion protocol, to 100% of fees diverted to the Treasury multisig for one year, or until new token distribution and reward schemes are implemented (source) - T3rn raises $6.5 million for bridge-free multi-chain interoperability - t3rn is currently working on developing an expressive protocol for making generalizable function calls across multiple chains that will allow for the composition of multi-step transactions across several chains with a single call, which is not possible with bridges (source) - DeFi protocol perennial launches, announces $12M in funding - Perennial is a decentralized-finance (DeFi) platform used to trade derivatives (source) #DeFi#December2022#trends

The Open Platform

@topco · Post #33 · 11.01.2023 г., 09:04

Metaverse: December headlines - BlackRock unveils metaverse and global SRI ETFs - Qontigo selects the top 10% of companies with High Quality Patents (HQP) in technologies ranging from 3D image modelling, avatars, blockchain, graphic processing units (GPU), non-fungible tokens (NFT) and virtual, augmented and extended reality, based on EconSight data (source) - Metaverse-first blockchain Lamina1 launches rolling fund for Web3 builders to provide them with a capital-raising tool for their open metaverse ventures and to offer investors a chance to get in on projects at the ground level (source) - South Korea’s wild plan to dominate the metaverse - the South Korean government has an ambitious $44.6 billion plan called the “Digital New Deal”, including $171.6 million earmarked to help South Korea become ranked No. 5 among the most metaverse-adopted countries in the world by 2026 — up from its current place at No. 12 (source) - Alibaba's E-Commerce Platform Braces For Its Metaverse Debut - Taobao conducted final tests before making its first metaverse live-streaming product, which will likely launch online around the upcoming New Year's shopping extravaganza (source) - Metaverse experience to sway real-world travel choices in 2023 - a survey participated by 24,179 respondents across 32 countries reveal that nearly half, or 43% of the respondents, intend to use virtual reality to inspire their choices (source) - Warner Music Group Furthers Metaverse Push With Digital Fashion Startup DressX - Warner and DressX want everyone to have a “meta-closet” full of digital wearables (source) #metaverse#December2022#trends

The Open Platform

@topco · Post #31 · 09.01.2023 г., 09:04

Crypto Payments: December headlines - Stripe debuts fiat-to-crypto payment offering for Web3 businesses - the widget allows customers to more easily use crypto to engage with businesses and content creators across the world (source) - Crypto.com receives license as a payment institution in Brazil, the company is the first crypto exchange to become a licensed payments institution in the South American country (source) - Visa released a technical paper in which it explored the possibility of developing an automatic payment system for self-custodial wallets on Ethereum (source) - South African digital-only bank launches crypto payments gateway - Be Mobile Africa has reportedly launched a crypto payment gateway that allows merchants to convert digital currency payments to fiat currency to "help small businesses preserve wealth in unfavourable economic conditions” (source) - Crypto Refills Labs releases a report on consumer adoption on crypto payments - according to report, cryptoshoppers are less worried about transaction fees, more interested in stablecoins and spend crypto more frequently (source) #paymentsolutions#December2022#trends

The Open Platform

@topco · Post #32 · 10.01.2023 г., 09:04

Web3 Creator Economy: December headlines - Impact Venture Capital invests in $8 million seed round for Web3 startup Virtualness - Virtualness is a mobile-first platform designed to help creators and brands navigate the complex world of Web3 (source) - Animoca Brands and its subsidiary TinyTap, the platform for user-generated educational games, announced that the second series of teacher-authored Publisher NFTs will be auctioned on OpenSea starting at 19:00 (EST) on 15 December, the firm’s recently introduced Publisher NFTs leverage Web3 technologies and community to improve earning opportunities for educators, create new earning and promotional options for co-publishers, and empower the community to directly support the growth of learning (source) - Web3 Game project Magic Fantasy has completed $3 M private round investment - Magic Fantasy is a strategic card game, which enables players to co-share the rewards of the game through winning in PvP season and will release the creation power of equipment, gameplay, etc, so as to motivate the players become creators (source) - Revel raises $7.8M to become the Instagram and Robinhood of NFT platforms - Revel is a cross between a social network and a marketplace meant to be a simple trading platform that’s gamified, allowing individuals to mint photos and videos as collectibles (source) #creatoreconomy#December2022#trends

The Open Platform

@topco · Post #30 · 06.01.2023 г., 09:04

Wallets: December headlines: - Crypto wallet BitKeep loses $8 million in ongoing hack - Bitkeep points to malicious APK packages (source) - Anonymous crypto wallet moves $80 million worth of Bitcoin onto Coinbase - cryptocurrency transfers from wallets to exchanges is typically a bearish signal (source) - Senator Warren introduces new crypto bill targeting self-custody wallets, the bill would expand KYC requirements for crypto network participants, is descibed by critics as “opportunistic” and “unconstitutional” (source) - Huobi releases a report on crypto wallet usage, highlights that crypto wallets users grew to 85 million in 2022 (6% increase) (source) - SafePal integrates support for TON - SafePal users will now be able to store and send the native $TON token within their hardware and software wallets. Additionally, it will be possible to directly interact with the Decentralized Applications (DApps) that currently exist on the TON blockchain (source) #wallets#December2022#trends