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

Резултати

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

Пребарај: #otradnoye

当前筛选 #otradnoye清除筛选
DruschbaFM - English

@druschbaFm_en · Post #52752 · 01.04.2025 г., 07:57

⚡️ 🇷🇺 🇺🇦⚔️ Ukraine Fronts on the Morning of 1 April⚡️ 🔴 In #Chernigov Direction, the AFU has reportedly already crossed the Russian border of the #Bryansk region many times. Locals point to periodic incursions towards several villages. 🔴#Sumy Direction: 🔴In #Sudzha Sector, to the west on Ukrainian soil, the situation based on confirmed information and evidence is as follows: 🟡#Vladimirovka- AFU; {1st blue↗️}; 🟡#Vodolagi - AFU; 🟡#Uspenovka in Russia - contested {1st black↘️}; 🟡#Veselovka - contested {2nd black↖️}; 🟡#Belovody - AFU; 🟡 In #Zhuravka, fights in the central part; 🟡 In #Basovka, the RFAF assaults the eastern part. 🟡#Novenkoye - RFAF {1st red⬆️}. 🟡 In #Kursk region, reportedly, Russian troops have repelled an assault on the 'Border Checkpoint' {2nd red↙️}; the AFU have reinforced the battle area around #Oleshnya {4th blue⬅️}. 🟡 In #Guyevo, the RFAF have reportedly extended their control zone {5th black⬇️}. 🟡#Gornal remains AFU controlled. 🔴In #KrasnayaYaruga Sector, reportedly positional battles are taking place in #Popovka {6th black↙️}. 🟡 In #Demidovka, the AFU have advanced in the central part and in the area of ​​the farm in the village's eastern part. 🗺 Map 2 🟡 At #Grafovka and #Prilesye, lull. 🗺 All on Map 1 🔴#Kharkov Direction: 🔴In #Liptsy Section, positional battles. 🔴 In #Volchansk Section, as well in the city itself. 🔴#Svatovo Front: 🔴 In #Kupyansk and #Borovaya Sectors, reportedly slight tactical successes for the RFAF without major changes. 🔴In #Liman Sector, fighting south of #Katerinovka and east of #Novoye in the north. 🔴In #Seversk Sector, west of #Belogorovka, Russian troops reportedly approached #Grigorovka. 🔴#ChasovYar Direction: 🔴In #ChasovYar Sector, the battles continues. 🔴In #Toretsk Sector, fighting in the city and to the west for #Shcherbinovka and #Leonidovka continued. 🔴#Pokrovsk Direction: 🔴 On the right Flank, far to the east, fighting continues at #Valentinovka and in the area of #Panteleymonovka (towards #Toretsk northwards). To the west, urban battles in #Tarasovka. 🔴 South of the City, reportedly Russian advance in #Lysovka. Battles at #Shevchenko and #Peschanoye, and in #Kotlino fighting at the the far southeastern edge. 🔴 On the left Flank, the fighting for #Udachnoye's far southeastern reportedly continued. Otherwise, intense combat is taking place along the entire frontline from #Solenoye southwards. 🔴#Komar Direction: 🔴In #Bogatyr Sector, the battles near #Andreyevka and for #Konstantinopol continue. 🟡 In #Razliv, Russian troops extended the zone of control and raised the flag in the centre of the village. 📌Despite several Russian claims, there is no takeover yet! The village boundaries extend to the west, especially the large buildings with blue roofs are located within them. 🎬 Video 🗺 Map 3 🔴 In #Komar Sector, the RFAF are reportedly attacking towards #Otradnoye and #Komar. 🟡 In #Vesyoloye, the battle for the settlement is ongoing. 🔴#Zaporozhye Direction: 🔴In the #Orekhov Section, south of the city, the AFU positions are reportedly under permanent fire; Russian units are attacking towards #Novoandreyevka. To the west, the fighting especially in the 4 contested villages continues: 🟡#Shcherbaki; 🟡#MalyeShcherbakito the west; 🟡#Stepovoye, further west; 🟡#Lobkovoye; 🟡#Pyatikhatki remains RFAF controlled. 🟡 At #Kamenskoye, in the far west, the RFAF reportedly took one of the AFU's key strongholds. 🔴 In #Kherson Direction, Russian aviation struck Ukrainian positions on the opposite bank, while the AFU targeted villages. 💥 For #OldRussia and #RestUkraine, we have found no reports of new mutual strikes. ⚠️ The Term 'Reportedly' indicates that it is unconfirmed! 🎞 Video Source 🗺 Maps @olegtsarov; @petrenko_iHS@creamy_caprice 📋 Sources: CC; Tsarov; 🇺🇦Fiend;⚡️2M;🐈Cat😼VK 🕰As of 1 Apr 2025; 06:38 GMT+3;📃31 Mar 📱 Join GLOBAL DEPTH to boost your TG Feed 💬Join Military Chat for Comments & Discussions 🇺🇦On Ukraine Observer you will find your daily independent Ukraine War Battle Update

DruschbaFM - English

@druschbaFm_en · Post #52668 · 29.03.2025 г., 08:06

⚡️ 🇷🇺 🇺🇦⚔️ Ukraine Fronts on the Morning of 29 March⚡️ 🔴#Sumy Direction: 🔴 At #Bryansk Border, mutual strikes. 🔴In #Sudzha Sector, to the west on Ukrainian soil, reportedly the RFAF is about to expand the zone of control on a broad front from #Vladimirovka up to #Basovka: 🟡#Vladimirovka- contested; 🟡#Vodolagi - AFU {2nd blue⬆️}; 🟡#Veselovka - taken by the RFAF {1st black⬆️}; 🟡#Belovody - AFU {3rd blue⬆️}; 🟡#Zhuravka - contested; 🟡#Basovka - contested. 🟡#Novenkoye, RFAF {1st red⬆️}. 🟡 In #Kursk region, reportedly, Russian forces advanced from the 'Border Checkpoint' {3rd red arrow} further south and have entered #Oleshnya 4th blue⬅️}. 🟡#Gogolevka, is reportedly RFAF controlled {2nd red⬇️}. 🟡 In #Guyevo, Russians filmed their presence in the village's north and fights further south {4th black⬅️}. 🎬 Video 1 🟡#Gornal remains under AFU control. 🔴In #KrasnayaYaruga Sector, militants enter #Popovka regularly up to its eastern part under RFAF fire {5th black↙️}. 🗺 Map 2 🟡 In #Demidovka, the AFU controls ca. 50% of the village. 🟡 At #Grafovka, lull. 🟡 At #Prilesye as well. 🗺 All on Map 1 🔴 In #Kharkov Direction, without changes. 🔴#Svatovo Front: 🔴 In #Kupyansk Sector, far north, Russian troops advanced in #Krasnoye1st. RF MoD claims its takeover. Further south, reportedly: 🟡#MalayaShapkovka has been entered; 🟡#Kondrashovka was taken and 🟡#Tischenkovka has been entered. 🔴 In #Borovaya, #Liman and #Seversk Sectors, and... 🔴#ChasovYar Direction, no major changes. 🔴#Pokrovsk Direction: 🔴 On the right Flank, far to the east, battles continue in the #Panteleymonovka area. To the west, for #Tarasovka. 🔴 South of the City, most of #Lysovka is RFAF controlled. 🔴 On the left Flank, the fighting (afore called clearing) continues in #Uspenovka. 🟡 In #Novoaleksandrovka, the battle for the village reportedly goes on. 🟡#Kotlyarovka has been approached by Russian troops. The AFU counterattack. 🟡 At #Bogdanovka, the RFAF advanced to the southern edge of the village. 🔴#Komar Direction: 🔴In #Bogatyr Sector (afore 'Konstantinopol Sector'), the RFAF advanced north of #Andreyevka in westerly direction and closed half of the pocket. Fighting continues to the west of the village (remember, previously the Russians were driven out of positions further west near #Alekseyevka). 🟡 In #Konstantinopol, Russian troops are still trying to regain control over the settlement. The AFU counterattack. 🟡 In #Razliv, the battle has reportedly shifted to the centre. 🟡On #Bogatyr, the RFAF are advancing on a broad front from the south. 🔴 In #Komar Sector, Russian troops move on #Otradnoye, located west of #Bogatyr. To the west, the battle for #Vesyoloye continue. 🔴#Zaporozhye Direction: 🔴In #Orekhov Section, positional fights in the are of​#MalayaTokmachka - #Rabotino area. Further west reportedly: 🟡 In #Shcherbaki, the battle continues with varying success. 🟡 In #MalyeShcherbakito the west, the RFAF try to get full control of the village. 🟡 In #Stepovoye, further west, the clashes continued. 🟡 In #Lobkovoye as well. 🟡#Pyatikhatki remains RFAF controlled. 🔴 In #Kherson Direction, the RFAF shelled AFU positions, the AFU, in turn, villages. 💥#Russia: 🔵 The AFU struck the 'Transmash Plant' in #Donetsk (#DPR); in #Lugansk (#LPR), the 'Industrial Zone'; in #Belgorod region, #Stroitel and several villages; and in #Kursk Region, again the 'Sudhza Gas Metering Station' and finished it off. 🎬 Video 2 💥#RestUkraine: 🔵 The RFAF, in turn, struck targets in the #Kiev, #Vinnitsa, #Zhitomir, #Kharkov, #Sumy, #Nikolayev, #Cherkassy, #Poltava, and #Chernigov regions, as well as in #Dnepropetrovsk. ⚠️ The Term 'Reportedly' indicates that it is unconfirmed! 🎞Vids Source 1; Source 2; 🗺 Maps @olegtsarov; @creamy_caprice 📋 Sources: CC; Tsarov; ⚡️2M; 🇺🇦Fiend;😼Kotenok 🕰As of 29 Mar 2025; 06:44 GMT+3;📃28 Mar 📱 Join GLOBAL DEPTH to boost your TG Feed 💬Join Military Chat for Comments & Discussions 🇺🇦On Ukraine Observer you will find your daily independent Ukraine War Battle Update