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

Резултати

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

Пребарај: #azovstal

当前筛选 #azovstal清除筛选
BadVolf

@BadvolfNews · Post #142 · 15.06.2022 г., 13:12

Here is the teaser for #Azovstal, my new movie! Are you ready for a powerful journey to one of the most treacherous places on the planet? You will only see it on my channel. View it in 4K at Youtube.com/c/JohnMarkDougan-BadVolf Or on Rumble (though not in 4K) https://rumble.com/user/BadVolf If you want to see this trailer in 4K, check out he link below: https://youtu.be/7Ro0R8DpxbU

Hashtags

BadVolf

@BadvolfNews · Post #138 · 13.06.2022 г., 14:56

Took a little stroll in #Azovstal today. I'll have incredible footage of the outside, and inside the bunkers, soon!

Hashtags

RTDocumentary

@rtdocumentary · Post #847 · 31.05.2022 г., 14:38

‘I don’t know what the Azov fighters were taking because they were going under their AGS, their SPG. Heavy shelling. An average person would hardly run towards their bursts because the chance of being hit is high,’ a Vostok battalion fighter, codenamed ‘Forest’, described the actions of Ukrainian nationalists at the Azovstal plant exclusively to RT Documentary. The plant is enormous, covering 11 square kilometres. It has underground spaces and long tunnels where the Ukrainian military hid from the shelling. This footage shows a fighter from the Vostok battalion explaining the DNR army's tactics in overpowering Azovstal and describing how and from where the fighting was launched. He also points out the remains of ammunition, the destroyed workshop and other premises after the surrender of the Ukrainian military. This episode will be included in our new film, premiering soon. #Ukraine#Azovstal Follow: https://t.me/rtdocumentary

На Азовстали продолжают находить свидетельства насилия над людьми. В ходе обследования территории военные обнаружили недавно использованную доменную печь с останками внутри и одеждой рядом. Найденное отправлено на экспертизу. Надеемся, что худшие ожидания не подтвердятся, хотя, когда речь идёт о сатанинском "Азове", удивляться уже нечему. Evidence of violence against people continues to be found at the #Azovstal plant. During the survey of the territory, the military found a recently used blast furnace with remains inside and clothes nearby. The found has been sent for examination. We hope that the worst expectations will not be confirmed, although when they talk about the satanic division "#Azov", there is nothing to be surprised about.

RTDocumentary

@rtdocumentary · Post #805 · 23.05.2022 г., 12:23

‘I told them [Azov fighters] that they were coming to life, I would have shot them myself... I don’t have an ounce of pity here...’ These are the words of labour veteran Tatyana Ivanovna. She lives in a village near Azovstal. Listen to her story of the Azov battalion shooting the animals in the area and how they almost killed her for trying to save her chickens. How they mocked her when she asked for water and food: I told their commander: ‘I want to eat, I haven’t eaten for six days …’ And he’s like: ‘I also want to’. But ‘DPR people... came, hugged me, one brought me stew, another brought me bread, and one even thought of bringing sweets’. We turned to the subjects of the film VolunTears. They helped Tatyana Ivanovna and other residents of the village of Uspenovka by bringing them food, water and medicine. #Ukraine#Mariupol#Azovstal Follow: https://t.me/rtdocumentary