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

Резултати

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

Пребарај: #bcmc

当前筛选 #bcmc清除筛选
AIRDROPS BOSS

@airdropsboss · Post #853 · 28.12.2021 г., 13:42

Dear community! 💙 BCMC1 People IEO Airdrop⬇️⬇️⬇️ @bcmc_peopleIEO_airdropbot ✅ Please complete all the tasks and submit details correctly. 💰 Rewards: - If you complete all tasks you will get 450 BCMC1. 📊Market: CoinMarketCap 💧BOUNTY💧 ⏰ Airdrop will end on (UTC) or when there are 5,000 participants. #BCMC1#BeforeCoinMarketCap#BCMC#Crypto#BCMCToken#Airdrop

AIRDROPS BOSS

@airdropsboss · Post #830 · 15.11.2021 г., 14:59

🚀BeforeCoinMarketCap NEW AIRDROP🚀 💵Total Reward: 550 BCMC1 💰 Value: $8 📊Market: CoinMarketCap click here⤵️ 💎Airdrop Bot💎 ☝️Don't miss out on MLM (Ongoing tokens sale with limited pool). 🥳 Invite buyers with your referral links and earn 10% GOOD LUCK TO EVERYONE!!!✊🏻 💠Telegram 💠Telegram Channel 💠Twitter 💠Facebook 💠LinkedIn 💠YouTube 💠Website #BCMC1#BeforeCoinMarketCap#BCMC#Crypto#BCMCToken#Airdrop

AIRDROPS BOSS

@airdropsboss · Post #854 · 31.12.2021 г., 10:57

💧BeforeCoinMarketCap BOUNTY💧 (For 100 participants only💯) Make a video about our platform: Post it on your official YouTube channel (3-5 minutes) $50 - $100 in BCMC1 token. We take into account the length and quality of the content. Example: Please watch this videos for instructions: https://youtu.be/8t1ucZFnyL8 & https://youtu.be/aYrpgGpI074 1 Best video will receive 15,000BCMC1 ($200) and will posted on our social channels.🏆 Mandatory: ✅Describe the People IEO. (Community voting) ✅Describe the People IEO. (Participant projects) ✅Explain the MLM system (Ongoing token sales) ❗️Notice: The channel must have Minimum of 1000 subscribers. Your email will be blacklisted if you submit an old video link or if you do not follow the instructions given. #BCMC1#BeforeCoinMarketCap#BCMC#Crypto#BCMCToken#bounty#Bounty

AIRDROPS BOSS

@airdropsboss · Post #829 · 13.11.2021 г., 08:32

💎 BeforeCoinMarketCap New BOUNTY 💎 For 100 participants only💯 Bounty Tasks✅ Make a video about our platform: Post it on your official YouTube channel (3-5 minutes) $50 - $100 in BCMC1 token. We take into account the length and quality of the content. 📍Mandatory: 1. Describe the search window. 2. Describe the Announcement window 3. Explain the MLM system (Ongoing token sales): 4. Describe the promotion website Best video will receive 20,000BCMC1 ($300) and will posted on our social channels. 📍Bounty Google Form Notice: The channel must have Minimum of 1000 subscribers. Your email will be blacklisted if you submit an old video link or if you do not follow the instructions given. #BCMC1#BeforeCoinMarketCap#BCMC#Crypto#BCMCToken#Bounty