Re: [Tutor] Fwd: find second occurance of string in line

2015-09-09 Thread Laura Creighton
Peter Otten
>Those who regularly need different configurations probably use virtualenv, 
>or virtual machines when the differences are not limited to Python.

Use tox for this.
https://testrun.org/tox/latest/

However for development purposes it often helps to have a
--force the_one_that_I_want option (for command lines) or
a global variable, or a config file for modules.

How badly you want this depends on your own personal development
style, and how happy you are popping in and out of virtualenvs.  Many
people prefer to write their whole new thing for one library (say
elementtree) and then test it/port it against the other 2, one at a
time, making a complete set of patches for one adaptation at a time.
Other people prefer to write their code so that, feature by feature
they first get it to work with one library, and then with another, and
then with the third, and then they write the next new bit of code, so
that they never have to do a real port.

Life is messy enough that you often do a bit of this and a bit of the
other thing, even if you would prefer to not need to, especially if
hungry customers are demanding exactly what they need (and we don't
care about the other ways it will eventually work for other people).

Laura
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: find second occurance of string in line

2015-09-08 Thread Peter Otten
Albert-Jan Roskam wrote:

>> import lxml.etree
>>
>> tree = lxml.etree.parse("example.xml")
>> print tree.xpath("//objectdata/general/timestamp/text()")
> 
> Nice. I do need to try lxml some time. Is the "text()" part xpath as well?
 
Yes. I think ElementTree supports a subset of XPath.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Fwd: find second occurance of string in line

2015-09-08 Thread Peter Otten
richard kappler wrote:

>> Do you want to find just the second occurence in the *file* or the second
> occurence within a given tag in the file (and there could be multiple such
> tags)?
> 
> There are multiple objectdata lines in the file and I wish to find the
> second occurence of timestamp in each of those lines.
> 
>> Is objectdata within a specific tag? Usually when parsing XML its the
> tags you look for first since "lines" can be broken over multiple lines
> and multiple tags can exist on one literal line.
> 
> objectdata is within a tag as is timestamp. Here's an example:
> 
> http://www.w3.org/2001/XMLSchema-instance;
> xsi:noNamespaceSchemaLocation="Logging.xsd"
> version="1.0">0381UDI132
> 2015-06-18T14:28:06.570
> 531630381UDI12015-06-18T14:27:50379
> 1306 oi="607360" on="379" ox="02503" oc="0" 
is="49787" ie="50312" lftf="N"
> lfts="7" errornb="0"
> iostate="DC00">2015-06-18T14:27:50.811 unit="inch">51.45 unit="ms">0... part.

Here's a way to get these (all of them) with lxml:

import lxml.etree

tree = lxml.etree.parse("example.xml")
print tree.xpath("//objectdata/general/timestamp/text()")


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor