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 слични објави

Пребарај: #celebrities

当前筛选 #celebrities清除筛选
Kursiv Uzbekistan (Eng)

@kursivuzeng · Post #2674 · 27.02.2026 г., 06:53

🌟 TIME Unveils 2026 Women of the Year List 👩 TIME has named 16 influential women from entertainment, sports, business and activism as its 2026 Women of the Year, celebrating their contributions to equality and social progress. 🎬 Honourees include actor-singer Teyana Taylor, Lucy Liu, Sheryl Lee Ralph, filmmaker Chloé Zhao, musician Brandi Carlile, and Olympic champion Sydney McLaughlin-Levrone. Authors, activists, and business leaders such as Mel Robbins, Mariska Hargitay, Amy Sherald, Reshma Kewalramani, Kecia Steelman, and Reshma Saujani are also featured. Humanitarian figures like Isata Dumbuya, Sister Norma Pimentel, Safeena Husain, and Mahnoor Omer are recognised for their grassroots impact. Read more on the website #Celebrities

Hashtags

Bali News

@balinews · Post #310 · 03.02.2025 г., 11:06

🎤 Usher feels happy in Bali 😎 R'n'B singer Usher visited Bali and called himself the happiest man in the world. 📱 In one of his latest posts, the rapper shared his joy of being in Bali and said he was enchanted by the island of gods. 👏 Subscribers supported him in high appreciation of the island and its beauties. @BaliNews #celebrities

Hashtags

Bali News

@balinews · Post #54 · 21.05.2024 г., 09:30

✈️Elon Musk flew to Bali for the first time to launch Starlink Photos of the founder Elon Musk in a traditional Balinese shirt and frangipani necklace have already traveled around the world. On the day of his arrival, he had time to participate with the country's President Joko Widodo in the opening of the World Water Forum and admire the nature of Bali. I'm amazed by the mangrove trees and this huge amount of greenery around, it's really cool. shared the Tesla founder did what he came for – he tested the Starlink internet service. @BaliNews #celebrities

Hashtags

Bali News

@balinews · Post #49 · 16.05.2024 г., 11:05

😮Elon Musk flies to Bali to unveil Starlink service SpaceX founder Elon Musk will be in Indonesia for the launch of the company's Starlink internet satellite service in the country on May 19. This was announced by the Minister for Investment, Mr. Luhut. The event is expected to take place alongside President Joko Widodo on the sidelines of the World Water Forum, which kicks off on the island on Saturday, May 18. Since the beginning of the year, the heads of two of the world's biggest technology companies have already visited Indonesia, promising major investments in the country. They are Apple CEO Tim Cook and his Microsoft counterpart Satya Nadella. @BaliNews #celebrities#events

Bali News

@balinews · Post #549 · 09.01.2026 г., 09:35

⭐️It looks like a movie featuring Gerard Butler may be filming in Ubud 📸 The actor has been spotted several times in the city center, calmly walking around, chatting with people, and taking photos with fans — without security or a film crew, dressed in casual everyday clothes, far from the usual Hollywood glamour. 👍 The very fact that a Hollywood star of this level can freely walk around Ubud and interact with locals has once again fueled conversations about Bali as a place where celebrities can be “just people,” rather than targets for paparazzi. What do you think — is this a film shoot, or is Butler simply vacationing on the island? #celebrities#Ubud@BaliNews

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