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

Резултати

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

Пребарај: #karagarga

当前筛选 #karagarga清除筛选
PT资讯频道

@PrivateTrackerNews · Post #773 · 03.08.2019 г., 16:27

#Karagarga (KG) Donations (2019) We have now collected all the funds required. Donations are closed again until 2020. Thank you for your contributions. We've also handed out all donor stars. If we missed you through administrative oversight, please contact ***. 捐款(2019年) 我們現在收集了所需的所有資金。 捐款將再次關閉,直到2020年。 感謝您的貢獻。 我們還發放了所有捐贈明星。 如果我們通過行政監督錯過了您,請聯繫***。

Hashtags

PT风向旗

@Ptfxq · Post #375 · 14.10.2022 г., 22:00

#karagarga#KG The Pot The pot system has been functioning well for more than a decade now, big thanks to all subtitlers and pledgers. Please check if you have claimed any pots. Go to your profile, and after Pot Pledges click on (claimed pots). If you are working on a pot, leave a comment there about progress, and update that post at least every 3 months. If not, cancel your claim. A dormant claim can discourage a potential subtitler. Also, please keep an eye from time to time on pots you started or pledged to (see Pot Pledges in your profile). If good subtitles appeared in the meantime, report that pot with a link to the subs. If you want to subtitle a film for which the pot has been claimed long ago without any news, please contact one of us (corvusalbus, flipflink, cyzs, musiclova). Happy subtitling and viewing!

PT风向旗

@Ptfxq · Post #279 · 28.07.2022 г., 23:35

#KaraGarga#KG#开放捐赠 2022-07-26 Annual Donations (2022) Dear all, we've to collect donations for server / hosting expenses for the year ahead. Please contact stefflbw by pm if you can contribute this year. If you have donated in 2020 or 2021 you can follow the same link / method. In that case please PM stefflbw (with the transaction details) when the donation is complete. If you do not wish to have a donor star activated beside your profile name, please let us know. "What is a suitable amount?" is a frequently asked question. Donations between $10 and $50 have been the most typical. Occasionally members have donated substantially more but the bulk of the annual bill is generally financed by a high number of "smaller" donations. We will post regular updates on the donations total percentage below. Thank you, the KG jungle gym team

PT风向旗

@Ptfxq · Post #926 · 16.08.2025 г., 16:00

#KaraGarga#KG#开放捐赠#慢讯#群友投稿 只是年度捐赠,没有捐入 Dear all, we are commencing our annual donations drive. The funds collected will cover server / hosting expenses from September 2025 to September 2026. How much might a member donate? A typical donation amount in previous years was $10 to $50. A few members have donated substantially more but the bulk of our funds is collected through a higher volume of typical donations. If you have the opportunity to donate in 2025, please PM () for instructions. (If you have donated previously, the instructions have not changed) Much love from The Crow Sanctuary boffins. Target percentage: Aug 3: 17% Aug 4: 28% Aug 5: 37% Aug 6: 47% Aug 7: 56% Aug 8: 69% Aug 9: 74% Aug 10: 77% Aug 11: 80% Aug 12: 85% Aug 14: 87% Aug 15: 90%