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

Резултати

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

Пребарај: #tik

当前筛选 #tik清除筛选
PT风向旗

@Ptfxq · Post #354 · 22.09.2022 г., 00:01

#Cinematik#TIK#站免 Autumn 2022 Freeleech! Once again Fall has set in and we'll have our traditional 7-day Freeleech. All torrents on site will be completely free to download until about 11PM CET on September 28. As usual, no uploading will be possible for the duration of the event, so take advantage and get rid of your bookmarks. Hopefully you may also revive some dead torrents. Beware: Don't forget to seed back everything you download to a 1:1 ratio, or for an absolute minimum time of 3 days - even spread over a week time. Hit-and-run behavior during freeleech entails from a several week warning to a final ban. Enjoy! With love from Staff

PT风向旗

@Ptfxq · Post #875 · 23.03.2025 г., 05:59

#Cinematik#TiK#站点免费 TiK 站免至 2025-03-31 23:59 (UTC) There it is, folks! It's time to celebrate Cinematik's birthday again. Your favorite tracker is now 19 years old, which is quite an amazing accomplishment! The festivities will start shortly, entailing a site-wide Freeleech that shall end at 23:59 (UTC) on 2025-03-31. In other words, the entire site will be in Golden mode for the duration of the event (9 days overall). We want to take this opportunity to extend our gratitude to everyone who has been and still is a part of this unique community. In particular, we are all very grateful to our wonderful uploaders, internals, and staffers, who volunteer their time and resources and work relentlessly towards keeping TiK as relevant and as strong as ever. And a special thank you to herrmann for creating this year's very colorful birthday banner!

PT风向旗

@Ptfxq · Post #556 · 27.01.2024 г., 07:02

#Cinematik#TIK#站点维护 We first must apologize for this sudden announcement and the short window of execution. The relaxed en-devour of moving our beloved Cinematik.net to a new server has been blocked by software incompatibility issues. This and the inability to stay on our current server (expires at the end of this month) has forced our new destiny earlier than planned. Ready or not we must embrace the newer UNIT3D code-base in its entirety and call it our new home. On Saturday the 27th 8pm GMT time our current server will go offline and the login screen will be replaced by the site landing page with the current status. Effective immediately new uploads are disabled and the approval thread locked to help negate further modifications to the server data. Please visit this thread for any further discussion. We hope you can join us in keeping a positive attitude going into our new home and allow it any benefit of doubt and time for you to get acquainted. Our new home should be ready by the 2nd of February

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