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

Резултати

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

Пребарај: #cinemageddon

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

@Ptfxq · Post #380 · 18.10.2022 г., 21:01

#Cinemageddon#CG Tis the season and today our Halloween freeleech begins. From now til an unspecified time after october 31 all horror and gore movies won't count up- or download. Enjoy, and have a happy halloween!

PT风向旗

@Ptfxq · Post #357 · 27.09.2022 г., 22:00

#Cinemageddon#CG#综合公告 Reward Threads It is great joy that we announce that all reward threads are up to date. Over 500 torrent descriptions were improved, nearly 1000 IMDB#s were added, and many custom creation and New to CG were paid on. It will now be our goal to award coins and complete updates and payments within hours instead of weeks or months. Now that so many of the torrent improvements have been provided and made, we would like to make a general call for any user who has an upload that needs the description improved to do it themselves. Improvements to your own descriptions or to those made through Improve Torrent Descriptions/Gain GBs! can be pointed out in The Pimp a Torrent Thread. This might bring some action back to torrents that may have been shunned due to their poor descriptions and lack of screens. Avatars I have noticed a few less users without avatars. The newest users seem to be the most reluctant to use them. I looked at the 100 newest users the other day and found that of the 36 that had ratios, only 4 had avatars. To help remedy this, we are looking for any of you still actively making avatars to help out with Avatar Request Thread. Users can offer credits to the avatar makers, or the avatar makers can just post interesting avatars and let the users decide how much to pay for them. Polls Seems the polls have become a topic of conversation, so A Poll discussion thread could be fun? has been moved to the General Forum. You can voice your thoughts on any of the polls here. As I said last month, we're doing what we can to make your experience at Cinemageddon as good as possible. We have not stopped trying to continually make it better.

PT风向旗

@Ptfxq · Post #326 · 28.08.2022 г., 22:32

#Cinemageddon#CG#综合公告 Avatars Did you find yourself with an avatar when you did not have one? Fear not, your account was not hacked, it's part of an effort to restore some fun to Cinemagddon. The forums have been rather blah lately and many posters had no avatars. When a cache of famous avatars was discovered going unused the idea to share them with these blank canvases came on like a light bulb. If you like your new avatar, keep it. If you do not like it, you can easily change or delete it. (Sorry for the trouble) If you have no avatar, maybe think about adding one. Keep an eye out for more avatar related news as it happens. Reward Threads Another ongoing effort to brighten up the place is taking care of the reward threads. You may also have noticed they are once again being attended to. There is still quite a bit of catching up to do in them, but progress is being made. We've taken care of over 60 torrent improvements in Improve Torrent Descriptions/Gain GBs! in the past couple weeks, but it still has about 400 torrents to be improved and paid on. We're doing what we can to make your experience at Cinemageddon as good as possible. And we will not stop trying to continually make it better. S.M.

PT风向旗

@Ptfxq · Post #476 · 11.11.2023 г., 08:00

#CinemaGeddon#CG#站点活动 It's November and that means Christmas competitions! CG Christmas Card Contest 2023 1st place 2500 credits + 200GB upload 2nd place 1000 cr + 100 GB upload 3rd place 500 cr + 50 GB upload and the worst of the bunch will get a lump of coal in the form of one credit (at least).