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

Резултати

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

Пребарај: #telegramthursday

当前筛选 #telegramthursday清除筛选

It's 'Telegram Thursday' and I want to recommend interesting channels. Today I was recommended a pretty fine channel, which focuses on Paganism: https://t.me/s/pagan_revivalism @Pagan_Revivalism Check it out and share if you like the content! The second channel I enjoy to check out every now and then is this one: https://t.me/s/folkwisdom @folkwisdom Pretty interesting forwards sometimes, from accelerationism to white pills. #TelegramThursday @EuropeanTribalism

It's 'Telegram Thursday' and I want to recommend interesting channels. Today I want to point out a channel dedicated to Germanic topics with lots of own content: https://t.me/s/oakwhispers @oakwhispers Give the creator a chance and check it out! It's important that we have channels like this, which add own content instead of plain forwarding. #TelegramThursday @EuropeanTribalism

It is 'Telegram Thursday' and I want to recommend you interesting channels. Today I would like to recommend a couple of channels I regularly read. No, not just content skipping, but actually reflecting on the content: https://t.me/tribeofthefox https://t.me/GreekLeague https://t.me/folkwisdom https://t.me/skogarvordurinn Go ahead and check them out! #TelegramThursday @EuropeanTribalism

It is 'Telegram Thursday' and I want to recommend you interesting channels. Today I would like to point out the channel from a lad I know from the time I was still on Twitter: https://t.me/AureusPress There is art, neo-futurism and quite some gems to be found on this channel. So go and check it! #TelegramThursday @EuropeanTribalism

I am not sure if everybody is aware that you can access all Telegram channels without having Telegram installed. You want to visit your favourite channel @EuropeanTribalism over your web browser? Try this: https://t.me/s/EuropeanTribalism You want to share the fantastic articles from @solarcult? Try this: https://t.me/s/solarcult Want to read one of @morrigancarrick's memes? Just add a number, which is the article ID at the end. Try this: https://t.me/s/morrigancarrick/533 Share it with your Telegram-free friends! #TelegramThursday @EuropeanTribalism

It's 'Telegram Thursday' and I want to recommend you some interesting channels: @PrimordialPath - a very interesting channel with straightforward opinions and views. If you are into Folk Futurism, go and check it out! @Solarcult - a channel devoted to mythology, history and Aryan heritage. Definetly worth a follow. @VolkischShakti - this channel focuses on information about female deities. If you are into mythology, it's worth to read it. Be sure to share quality content when you find it! #TelegramThursday @EuropeanTribalism

It is 'Telegram Thursday' and I want to recommend you some interesting channels: @philosophicat, who also runs a youtube channel by this name, adds a very unique perspective to current happenings. Also check out her series on Evolas 'Revolt Against the Modern World'! @aryologia has lots of interesting content if you are interested in Indo-Aryan culture. @mythologicalfact focuses on Vedic content. If you want to extend your knowledge about ancient myths, be sure to give them a follow. @getthispdf is my channel for collecting interesting eBooks for the topics physics, spirituality and history. If you want a good read, check it out. Be sure to share quality content when you encounter it! #TelegramThursday @EuropeanTribalism

It's 'Telegram Thursday' and I want to recommend you interesting channels. Today marks the first of a series of recommendations, based on the various expressions of European culture. We start with a channel, which focuses on the Slavic aspect: https://t.me/THEOLDWAYS Have a look and follow! #Slavic#TelegramThursday @EuropeanTribalism

12
ПретходнаСтраница 1 од 2Следна