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

Резултати

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

Пребарај: #meningitis

当前筛选 #meningitis清除筛选

Bacterial meningitis leaves 1 in 5 people with disabilities such as hearing loss, brain damage and limb loss. But meningitis is largely vaccine-preventable! Parents/caregivers are urged to visit any primary health care centre to get their children/wards vaccinated against #meningitis.

Hashtags

Your input is crucial in shaping better prevention, treatment and control strategies against #Meningitis in Nigeria. 📋Take our #Meningitis KAP Survey to share your knowledge, attitudes, and practices. 🔗Survey link https://forms.gle/R5uxSdet2nPNQvpRA

Hashtags

#Meningitis is a serious infection that can lead to severe complications & death Report immediately to a healthcare facility if you or a loved one experiences ➡️Neck pain ➡️Pain on looking at bright lights ➡️Vomiting ➡️Muscle/joint/limb pain ➡️Rash ➡️Seizures ➡️Cold hands & feet

Hashtags

Any form of #Meningitis is an emergency! ALL healthcare workers are urged to have a high index of suspicion and immediately report if they notice these signs & symptoms in their patients: ➡️Fever/severe headache ➡️Vomiting ➡️Drowsiness ➡️Rash ➡️Seizures ➡️Muscle/joint pain ➡️Stiff neck

Hashtags

The spread of #meningitis is usually through: ➡️ Direct person-to-person contact, including droplets from the nose and throat of infected persons. ➡️Close and prolonged contact with an infected individual. Visit the nearest health facility immediately if you notice any of the CSM-associated signs and symptoms.

Hashtags

#Meningitis is an inflammation of a thin layer of the connective tissue that covers the brain and the spinal cord. This inflammation can be caused by infection with bacteria, viruses, parasites, fungi, injuries and certain drugs. Know the symptoms to seek early health care. Advisory: https://ncdc.gov.ng/news/508/cerebrospinal-meningitis-public-health-advisory

Hashtags

#Meningitis is an epidemic-prone disease requiring immediate reporting in Nigeria. ALL healthcare workers are urged to have a high index of suspicion if they notice these signs & symptoms in their patients: ➡️Fever/severe headache ➡️Vomiting ➡️Drowsiness ➡️Rash ➡️Seizures ➡️Muscle/joint pain ➡️Stiff neck

Hashtags

Bacterial meningitis is largely vaccine-preventable; #meningitis vaccines are safe, effective, and give protection to your family and community. Parents and caregivers, now is the time to catch up on the childhood immunisations that protect against meningitis.

Hashtags

Hand washing is one of the most effective ways of preventing the spread of infectious diseases including #meningitis Always wash your hands with soap under running water for protection against meningitis and other deadly diseases Also ensure you and your loved ones are vaccinated with the recommended immunisations

Hashtags

Report immediately to a healthcare facility if you or a loved one experiences the below symptoms of #Meningitis ➡️Neck pain ➡️Pain on looking at bright lights ➡️Vomiting ➡️Muscle/joint/limb pain ➡️Rash ➡️Seizures ➡️Cold hands & feet Early recognition saves lives

Hashtags

ПретходнаСтраница 1 од 5Следна