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

Резултати

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

Пребарај: #complicity

当前筛选 #complicity清除筛选
MessageInABottle

@mib_messageinabottle · Post #6992 · 27.05.2024 г., 19:03

ICC CASE AGAINST URSULA Von Der LEYEN - FOR COMPLICITY IN WAR CRIMES AND CRIMES AGAINST HUMANITY IN GAZA Today the International Criminal Court (#ICC) has been officially called to investigate Ursula von der Leyen for #complicity in acts of #Genocide. Reasonable grounds exist to believe that the unconditional support of the president of the #European Commission to #Israel – #military, #economic, #diplomatic and #political – has enabled #WarCrimes and the ongoing genocide in #Gaza. – A communication is submitted today to the Office of the Prosecutor of the International Criminal Court (ICC), setting forth in detail, through facts and evidence, that there are reasonable grounds to believe that the current president of the European Commission, Mrs. Ursula von der Leyen, a national of Germany, is complicit in a number of violations of international humanitarian law, amounting to crimes within the jurisdiction of the ICC, committed by the Israeli armed forces (#IDF) against #Palestinian civilians in the #Occupied Palestinian Territory (#OPT), including the #Gaza Strip. This communication, endorsed by various human rights groups and prominent academics and experts in international criminal law, calls the Prosecutor to initiate investigations on the basis of the information provided against Mrs. Ursula von der Leyen. The communication documents in detail the fact that Mrs. Ursula von der Leyen personally is criminally responsible and liable for punishment for some of the war crimes, #CrimesAgainstHumanity and #genocide having been committed (and still being committed) by the Israeli armed forces in the #OPT, to the extent that she has aided, abetted and otherwise assisted in the commission or attempted commission of such crimes, including providing the means for its commission, in the meaning of Article 25(3)(c) of the #RomeStatute of the #ICC. MRS. VON DER LEYEN ENJOYS NO FUNCTIONAL IMMUNITY BEFORE THE ICC BY VIRTUE OF ARTICLE 27 OF THE ROME STATUTE.