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

Резултати

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

Пребарај: #qalqilya

当前筛选 #qalqilya清除筛选
RNN Archive

@rnn_archive · Post #591 · 16.09.2023 г., 21:03

The Azzun Phenomenon: Our attentive readers may have noticed updates every now and then about settlers being injured by stones or Molotovs in the modest town of Azzun, #Qalqilya: a simple search yields about 60 such reported operations in the last year. These operations, while simple, turn out to be very effective at shattering settler security. Azzun's stone-throwing prowess is not a coincidence, and in fact, the choice to carry out these operations here is a strategic one. The town of just 8,000 residents and 9 kilometers squared—which has offered 80 prisoners and five martyrs in recent years—is located at a historically important crossroads. Yet, this small town has become a nightmare for settlers. In August, at least 25 settlers were wounded by such operations in Azzun alone, rivaling injuries of resistance strongholds such as Jenin and Nablus. Last week there, four settlers were wounded and nearly a dozen of their cars were destroyed in one day. Settlers here are specifically targeted on a major vein of zionist infrastructure: settler bypass road Route 55, passing through Azzun. This road has actually been around since 300 BC. It was established formally in 1935, and this racist road was blocked often by Palestinians during the first intifada. As a result, the occupation built a number of alternative bypass roads. In 2002 amidst the second intifada, it became a settler bypass road, with its purpose being to give settlers a Jewish-only detour such that they can avoid the apparent danger of Palestinian areas. This stone-throwing has become a major problem for the occupation, who increased its security on Qalqilya for almost two months now, arresting a number of alleged stone-throwers. Today, the steadfast resistance of Azzun continue to create nightmares for settlers despite the siege, shattering their glass, destroying their cars, and targeting them with rudimentary explosive devices made at home. In all forms, resistance increases, and Azzun marches on the path of Jenin, Nablus, Tulkarem, and Gaza.

Hashtags

Resistance News Network Mirror

@PalestineResist_Mirror · Post #4566 · 01.05.2026 г., 00:04

🚨 IOF units are conducting a widespread campaign of raids and incursions across occupied Palestine, with operations concentrated in #Nablus, #Qalqilya, and #AlKhalil. Concurrently, armed settlers are launching violent assaults with live fire against residential areas in the vicinity of Al-Arroub camp. Settler provocations are also reported across the Nablus district.

RNN Mirror

@Palresistmirror · Post #94010 · 01.05.2026 г., 00:04

🚨 IOF units are conducting a widespread campaign of raids and incursions across occupied Palestine, with operations concentrated in #Nablus, #Qalqilya, and #AlKhalil. Concurrently, armed settlers are launching violent assaults with live fire against residential areas in the vicinity of Al-Arroub camp. Settler provocations are also reported across the Nablus district.