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

Резултати

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

Пребарај: #socialjustice

当前筛选 #socialjustice清除筛选

डॉ. बाबासाहेब अम्बेडकर का सामाजिक न्याय और समानता विज़न, एक समावेशी व कल्याणकारी समाज की दिशा में सरकार के प्रयासों को मार्गदर्शन प्रदान कर रहा है। #AmbedkarJayanti#SocialJustice#Equality

Hong Kong Democracy Movement

@hkdmovement · Post #7928 · 13.01.2025 г., 00:15

前香港立法會議員及囚犯權益活動家邵家臻於55歲去世,因癌症病情惡化。他在2016年當選,並創立了囚犯權益支持團體Wall-fare,幫助因2019年抗議而被囚禁的人士。 邵家臻的妻子在社交媒體上表示,他在家人和朋友的陪伴下安詳辭世。雖然他經歷了艱難的病痛,但他始終感受到信仰的指引與關懷。 社會工作者和活動家們紛紛表達悼念,前立法會議員張超雄稱讚他的社會正義理念及對弱勢群體的關懷將永存。 「在藍天下好好生活,繼續播下牆花種子。」邵家臻的精神將永遠激勵我們。 #邵家臻#悼念 Former Hong Kong lawmaker and prison rights activist Shiu Ka-chun has passed away at 55, following a worsening cancer diagnosis. Elected in 2016, he founded Wall-fare, a support group for those imprisoned over the 2019 protests. His wife shared on social media that he passed away surrounded by family and friends. Despite his struggles, he felt the guidance and care of his faith. Condolences have poured in from social workers and activists, with former lawmaker Fernando Cheung praising Shiu’s commitment to social justice and concern for the underprivileged. “Live well under the blue sky, and keep planting wallflowers.” Shiu's spirit will forever inspire us. #ShiuKaChun#PrisonRights#SocialJustice

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40137 · 20.11.2025 г., 03:02

Child marriage remains legal in 34 U.S. states, with some setting no minimum age. Over 314,000 minors were married in the last two decades, mostly girls to adult men. Efforts to ban it face ongoing political resistance. 🚨👧💍 The highest rates of child marriage in the United States are found in Texas, Florida, Kentucky, North Carolina and Alabama. [Read more] @googlefactss #ChildMarriage#HumanRights#USLaw#GenderEquality#SocialJustice#ChildrensRights

ℹ Did you know the Kyrgyz Republic has transformed its mountainous identity into a powerful diplomatic platform at the UN, driving the creation of multiple global observances and action plans? Since joining the UN, Kyrgyzstan has been a dynamic force in the General Assembly, securing long-term international recognition in three key areas: 🔹Mountain Leadership: Kyrgyzstan is the world’s leading advocate for mountains, initiating the Five Years of Action for Mountain Development (2023–2027) and establishing the International Day of the Snow Leopard (October 23). It also founded the Group of Friends of Mountain Countries (31 members). 🔹Security & Social Justice: The country successfully championed the International Day of Disarmament and Non-Proliferation Awareness (March 5) and was instrumental in creating the World Day of Social Justice (February 20). It also contributes to regional safety with resolutions on the Central Asian Nuclear-Weapon-Free Zone and the radiation threat in the region. 🔹Cultural Milestones: Secured UN commemoration for the millennium of the national epic, Manas (1994), and the Year of Kyrgyz Statehood (2002). Kyrgyzstan's diplomacy showcases how a small nation can achieve major global impact. #UNGA#Diplomacy#Kyrgyzstan#SustainableDevelopment#MountainDevelopment#GlobalSecurity#SocialJustice Follow us on social media and stay informed: LinkedIn | Instagram | X (Twitter) | Facebook | YouTube

Google Facts™ [ ️@googlefactss🌎]

@googlefactss · Post #40124 · 18.11.2025 г., 21:02

📜 The word "rape" has a complex and shifting history. Originally, it meant “to seize by force” — as in property or land. By the 1400s, it began to take on its modern meaning of sexual violence. Recent political attempts to create categories like "forcible rape" have been widely criticized for minimizing survivors' experiences. Language matters — especially when it comes to defining violence and consent. [Read more for more meanings] @googlefactss#LanguageHistory#Etymology#Rape#Consent#SocialJustice#LanguageMatters