A
A
Alexsem52017-09-19 06:12:10
Python
Alexsem5, 2017-09-19 06:12:10

Python. How to implement a search for text in xml starting with certain letters?

Good afternoon!
Thanks in advance to everyone for the hints that help me figure out Python.
I'm trying to implement a text search in xml starting with certain letters.
I work with xml file through element tree.
Source tags in xml:
brn_just_text
msk_just_text
I need to select the text by the first 4 characters, i.e., for example, if the text contains brn_, then I do ...
At the moment I have implemented only a search with a full occurrence of the text like this:
if item.find ('.//Caption').text == 'brn_just_text':
I tried to do this:
if item.find('.//Caption').text.startswith() == 'brn_':
Please tell me how to implement ?
Thanks everyone! Don't kick too hard. newbie and in python and with xml I work in detail for the first time;)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vlad Grigoriev, 2017-09-19
@Vaindante

It is very bad to refuse to use the search engine. tyts and tyts

A
Alexsem5, 2017-09-19
@Alexsem5

figured it out a bit, implemented it like this:
if item.find('.//Caption').text.startswith('brn_'):
Now it searches for everything that starts with brn_ successfully)
Maybe there are some other more correct options?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question