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

Резултати

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

Пребарај: #pollution

当前筛选 #pollution清除筛选
Amazing Geography 🌍

@amazingeo · Post #308 · 28.09.2025 г., 18:31

🌍 Over 90% of the world’s plastic is not recycled, and much ends up in the oceans. Ocean plastic has been found in Arctic ice and inside some of the deepest-living sea creatures. ✨ #pollution⚡#environment⚡#oceans⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

世界观察日志

@WorldObservationLog · Post #1334 · 02.09.2022 г., 08:26

近期,台湾有用户称在访问 Google 时被网页提示涉及诈骗。受影响的网站还包括 Google 地图及部分新闻网站。ISP 台湾大哥大解释称,问题原因是当日执行防诈骗相关测试。部分网友由此联想到近期通过的《中介法》,认为这可能是台湾 ISP 大规模屏蔽内容的开始。 台湾 NCC 近期通过《數位中介服務法》(简称中介法)草案,称仿效欧盟 Digital Services Act,要求平台对内容进行监管,产生一些争议。有观点认为法律规范不明确,且平台实际管理困难,恐损害言论自由。 https://tw.news.yahoo.com/google首頁被警告是詐騙-044720539.html 1. https://tw.news.yahoo.com/數位中介服務法-數位中介法-中介法-言論自由-正反意見-110307205.html #Taiwan#DNS#Pollution

Amazing Geography 🌍

@amazingeo · Post #573 · 13.01.2026 г., 12:31

🌍 Russia’s Lake Karachay is so contaminated from past nuclear waste that standing on its shore for just an hour could be fatal—one of the most polluted lakes on the planet. ✨ #rivers⚡#lakes⚡#pollution⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #347 · 08.10.2025 г., 15:31

🌍 Air pollution now causes more deaths worldwide than unsafe water or malaria, with tiny particles harming lungs and hearts. Even remote regions like the Himalayas register rising airborne pollutants. ✨ #pollution⚡#health⚡#climate⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #30 · 10.08.2025 г., 14:31

🌍 The Great Pacific Garbage Patch is a floating area of plastic and debris in the Pacific Ocean, now estimated to be more than twice the size of Texas. It affects sea life far beyond its borders. ✨ #pollution⚡#ocean⚡#plastics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #570 · 11.01.2026 г., 20:31

🌍 The Great Pacific Garbage Patch, a swirling mass of plastic debris, now covers an area larger than Germany. Ocean currents trap millions of tons of waste here, creating a persistent global pollution hotspot. ✨ #pollution⚡#oceans⚡#plastics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

Amazing Geography 🌍

@amazingeo · Post #77 · 19.08.2025 г., 13:12

🌍 Light pollution from cities is so widespread that more than 80% of the world's population can no longer see the Milky Way at night, affecting wildlife and our connection to the night sky. ✨ #environment⚡#pollution⚡#light⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #27 · 10.08.2025 г., 14:03

🌍 Tiny plastic particles, called microplastics, have been found in remote places like Arctic snow and deep-sea trenches, showing how far pollution can travel across the planet. ✨ #environment⚡#pollution⚡#microplastics⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍

Amazing Geography 🌍

@amazingeo · Post #691 · 15.04.2026 г., 20:31

🌍 Air pollution is now the world’s leading environmental health risk, causing more than 6 million early deaths yearly—fine particles from burning fuel can travel and harm people far from their source. ✨ #pollution⚡#health⚡#global⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography 👉more Channels ​

MALI 24

@kamissokosekou3 · Post #36533 · 27.04.2026 г., 09:39

https://t.me/kamissokosekou3 ⚠️ Falémé : pollution alarmante, un fleuve vital en danger Le fleuve Falémé, essentiel entre Mali, Sénégal et Guinée, est fortement menacé par la pollution liée à l’activité minière. Présence de cyanure, raréfaction des poissons, risques sanitaires : la situation inquiète particulièrement dans la région de Kéniéba. 👉 Faut-il renforcer les contrôles miniers pour sauver la Falémé ? Réagissez et partagez. NB: image d'illustration générée par IA. #Mali#Environnement#Faleme#Pollution#Afrique#ecologie La rédaction

籽煤 yseedsmedia

@yseedsmedia · Post #432 · 20.12.2021 г., 04:58

全球關注環境污染問題,印度是全球排行第三的碳排放國家,僅次美國及中國。為了可以大幅提升可再生能源的使用率及在2070年實現零碳排,同時為降低對中國太陽能材料的依賴,印度宣布將「打造本土太陽能供應鏈」。 外媒分析,中國在太陽能供應鏈市場一直有領導地位,全球達四分之三的太陽能板材料由中國生產出及供應。如果印度未能完善執行計畫,恐造成國內太陽能電池板成本飆升,當地工廠恐怕要蒙受巨大損失。 #印度#環境污染#碳排放#美國#中國#可再生能源#零碳#太陽能#供應鏈#中共#印度加油#india#pollution#carbondioxide#china#USA#supplychain#sunlight #yseedsmedia#籽煤#新聞#熱門新聞#香港人的新聞#香港人#hongkonger#香港加油 Follow and share us: IG: instagram.com/yseedsmedia/ Fb: fb.com/yseedsmedia Tg: t.me/yseedsmedia