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

Резултати

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

Пребарај: #solar

当前筛选 #solar清除筛选
Indian Development News 🇮🇳

@developmentnewsindia · Post #44371 · 03.05.2026 г., 13:50

Tata Power Renewable Energy Limited (TPREL) received board approval to invest ₹6,500 crore to establish a 10 GW photovoltaic ingot and wafer manufacturing facility. The project will be developed in two phases of 5 GW each, likely at a greenfield site in Nellore, Andhra Pradesh, with an estimated payback period of five years. This strategic expansion into upstream manufacturing allows Tata Power to achieve backward integration, significantly reducing reliance on Chinese imports while aligning with India’s ALMM framework to strengthen the domestic solar supply chain. Source #MakeInindia#solar

Indian Development News 🇮🇳

@developmentnewsindia · Post #44370 · 03.05.2026 г., 13:40

Andhra Pradesh Chief Minister N Chandrababu Naidu will lay the foundation stone for ReNew Energy Global plc's Rs 5,400 crore solar manufacturing facility in Anakapalli district. This 6 GW solar ingot and wafer unit marks a significant step in India's push for domestic clean energy manufacturing and energy security, aligning with the state's Integrated Clean Energy Policy 2024 Source #MakeInindia#solar

Interesting Planet 🌍

@interesting_planet_facts · Post #864 · 05.10.2025 г., 20:11

🌎 Pluto, once called the ninth planet, orbits in the distant Kuiper Belt and takes about 248 Earth years to complete one orbit around the Sun. ✨ #planets⚡#astronomy⚡#solar-system 👉subscribe Interesting Planet 👉more Channels ​

Interesting Planet 🌍

@interesting_planet_facts · Post #664 · 31.08.2025 г., 18:22

🌎 Jupiter’s Great Red Spot is a giant storm larger than Earth and has been raging for at least 350 years, swirling powerful winds nonstop across the planet’s atmosphere. ✨ #planets⚡#astronomy⚡#solar 👉subscribe Interesting Planet ​

Amazing Geography 🌍

@amazingeo · Post #205 · 09.09.2025 г., 13:12

🌍 On rare occasions, the aurora can be seen far from the poles, reaching as far south as Texas or southern Europe during strong solar storms. Their shifting shapes can move faster than a cheetah runs. ✨ #aurora⚡#atmosphere⚡#solar⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Amazing Geography 🌍

@amazingeo · Post #222 · 12.09.2025 г., 09:12

🌍 Earth travels around the Sun at nearly 30 kilometers per second. This speedy journey means our planet covers more than 940 million kilometers every year as it orbits through space. ✨ #Earth⚡#orbit⚡#solar⚡#geography⚡#nature⚡#earth 👉subscribe Amazing Geography🌍 ​

Love Nature

@LovelyNature · Post #1501 · 09.05.2021 г., 15:53

Japan is home to 73 of world's 100 largest floating #solar plants they prevent water evaporating, and help secure reservoirs in water-stressed countries. - #Japan#Naturehttps://twitter.com/i/status/1391177362927198211@LovelyNature

Online Education

@OnlineEducation10 · Post #327 · 09.05.2021 г., 15:53

Japan is home to 73 of world's 100 largest floating #solar plants they prevent water evaporating, and help secure reservoirs in water-stressed countries. - #Japan#Naturehttps://twitter.com/i/status/1391177362927198211@OnlineEducation10

Universe Mysteries 🪐

@cosmomyst · Post #721 · 24.03.2026 г., 22:21

🪐 NASA and ESA are collaborating on future missions to develop solar sail technology—a method that harnesses sunlight for propulsion—to power lightweight spacecraft toward nearby stars like Alpha Centauri. Unlike rockets, solar sails use the gentle push of photons (tiny particles of light) from the Sun to gradually accelerate, making it possible for small probes to reach interstellar space without carrying any fuel onboard. ✨ #spaceships⚡#interstellar⚡#solar⚡#nasa⚡#galaxy⚡#stars⚡#astronomy⚡#universe⚡#cosmos⚡#space 👉subscribe Universe Mysteries 👉more Channels ​

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