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

Резултати

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

Пребарај: #buildonton

当前筛选 #buildonton清除筛选
DWF Labs Broadcast

@Dwflabs · Post #173 · 22.01.2023 г., 09:54

​Now is the time and we are building!💎 The Open Network (TON) is growing strong developer communities in countries across the globe as our Hackathon provides developers with the necessary resources and guidance to build something incredible.🔥 Super excited to announce our INVITE-ONLY, on-site events. During our Hackathon this February, we will invite 6~10 teams that are looking to #buidl on #TON in a city that could be near you! Our goal is to empower builders and developers in local communities to create innovative applications, services and protocols with The Open Network. For the event, builders and developers will get a chance to meet and ask questions to a member of The TON Foundation and local TON developer specialist(s). The Q&A session will ensure that builders and developers are well equipped with knowledge about TON tools, incubation opportunities and building on TON mainnet. Join us on our mission to unite all blockchains and Web2 internet into one open network! If you want to attend and are excited to #BuildOnTon, please submit an introduction and your BUIDL idea! 🤓💻 To be eligible to WIN exclusive access, please abide by the following criteria: - Max. two people per team - Max. 150~250 words per pitch - Keep it concise and clear - Focus on value for the TON community - Submission period: Jan 18 (Wed) ~ Jan 25 (Wed) We are super keen to have developers from all over the world join us on our mission to build the next-gen internet. So, what are you waiting for? 💎SUBMITyour idea! The schedule of offline events during the TON global hackathon: Feb. 11-12: Taipei Seoul Bangkok Prague Feb. 18-19: Dubai Tel Aviv Tokyo Istanbul Singapore Feb. 25-26: Hong Kong Melbourne Saint Petersburg Hyderabad London

DWF Labs Broadcast

@Dwflabs · Post #165 · 20.01.2023 г., 00:00

​Now is the time and we are building!💎 The Open Network (TON) is growing strong developer communities in countries across the globe as our Hackathon provides developers with the necessary resources and guidance to build something incredible.🔥 Super excited to announce our INVITE-ONLY, on-site events. During our Hackathon this February, we will invite 6~10 teams that are looking to #buidl on #TON in a city that could be near you! Our goal is to empower builders and developers in local communities to create innovative applications, services and protocols with The Open Network. For the event, builders and developers will get a chance to meet and ask questions to a member of The TON Foundation and local TON developer specialist(s). The Q&A session will ensure that builders and developers are well equipped with knowledge about TON tools, incubation opportunities and building on TON mainnet. Join us on our mission to unite all blockchains and Web2 internet into one open network! If you want to attend and are excited to #BuildOnTon, please submit an introduction and your BUIDL idea! 🤓💻 To be eligible to WIN exclusive access, please abide by the following criteria: - Max. two people per team - Max. 150~250 words per pitch - Keep it concise and clear - Focus on value for the TON community - Submission period: Jan 18 (Wed) ~ Jan 25 (Wed) We are super keen to have developers from all over the world join us on our mission to build the next-gen internet. So, what are you waiting for? 💎SUBMITyour idea! The schedule of offline events during the TON global hackathon: Feb. 11-12: Taipei Seoul Bangkok Prague Feb. 18-19: Dubai Tel Aviv Tokyo Istanbul Singapore Feb. 25-26: Hong Kong Melbourne Saint Petersburg Hyderabad London