Xpath – Selecting attributes using starts-with

I am trying to write an xpath expression that selects all div tags that have an attribute id that start with CompanyCalendar. The following expression is perhaps what you are looking for: //div[starts-with(@id,’CompanyCalendar’)] What it does, in plain English, is Return all div elements in the XML document that have an attribute id whose attribute … Read more

What is the easiest way to get all strings that do not start with a character?

Use generator expressions, the best way I think. for line in (line for line in x if not line.startswith(‘?’)): DO_STUFF Or your way: for line in x: if line.startswith(“?”): continue DO_STUFF Or: for line in x: if not line.startswith(“?”): DO_STUFF It is really up to your programming style. I prefer the first one, but maybe … Read more

Why is string’s startswith slower than in?

As already mentioned in the comments, if you use s.__contains__(“XYZ”) you get a result that is more similar to s.startswith(“XYZ”) because it needs to take the same route: Member lookup on the string object, followed by a function call. This is usually somewhat expensive (not enough that you should worry about of course). On the … Read more

Case-insensitive string startswith in Python

You could use a regular expression as follows: In [33]: bool(re.match(‘he’, ‘Hello’, re.I)) Out[33]: True In [34]: bool(re.match(‘el’, ‘Hello’, re.I)) Out[34]: False On a 2000-character string this is about 20x times faster than lower(): In [38]: s=”A” * 2000 In [39]: %timeit s.lower().startswith(‘he’) 10000 loops, best of 3: 41.3 us per loop In [40]: %timeit … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)