Re: [Tutor] Python scope and variable binding

2013-11-28 Thread eryksun
On Wed, Nov 27, 2013 at 10:04 AM, Arnaud Legout wrote: > > example 4: > > x = "x in module" > class A(): > print "A: " + x > x = "x in A" > print "A: " + x > print locals() > del x > print locals() > print "A: " + x > A: x in module > A: x in A > {'x': 'x in A', '_

Re: [Tutor] string codes

2013-11-28 Thread Steven D'Aprano
On Wed, Nov 27, 2013 at 10:20:03PM +0100, spir wrote: > On 11/26/2013 12:59 PM, Steven D'Aprano wrote: > >On Tue, Nov 26, 2013 at 10:01:14AM +, Alan Gauld wrote: > > > >>>Is there a method to compare a substring, without building a substring > >>>from the big one? Like startswith or endswith, b

Re: [Tutor] Pretty printing XML using LXML on Python3

2013-11-28 Thread eryksun
On Thu, Nov 28, 2013 at 2:12 PM, SM wrote: > Run with Python3: > > $ python3 testx.py > b'\n \n some text\n\n' print() first gets the object as a string. tostring() returns bytes, and bytes.__str__ returns the same as bytes.__repr__. You can decode the bytes before printing, or instead use toun

[Tutor] Pretty printing XML using LXML on Python3

2013-11-28 Thread SM
Hello, I am using lxml with Python3, to generate xml code. "pretty_print" doesn't seem to indent the generated lines. I have installed the following lxml package: /usr/local/lib/python3.2/dist-packages/lxml-3.2.4-py3.2-linux-x86_64.egg/lxml The following is the example code I found on stack overf

Re: [Tutor] Nested for loops

2013-11-28 Thread Rafael Knuth
> Do you understand how that works? Yep. It's crystal clear now. Thank you. It took a while till I got it, though ;-) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] string codes

2013-11-28 Thread spir
On 11/28/2013 02:34 AM, Alan Gauld wrote: Not so. If you are looking for a string and know the string ends with that string you want the end point to exclude the known result at the end. And it is a startswith because you are checking from the start of the substring. Ah, thank you, Alan! Denis

Re: [Tutor] string codes

2013-11-28 Thread spir
On 11/28/2013 02:12 AM, Walter Prins wrote: Sorry to wade in after all the other answers you've had, but a) string.find() does not *require* start and end indexes, they are optional: http://docs.python.org/2/library/string.htmlAnd b) if you're just trying to find out whether a substring exist

Re: [Tutor] building table from textfile

2013-11-28 Thread Oscar Benjamin
On 27 November 2013 18:22, Ruben Guerrero wrote: > Dear tutor. > > I am trying to build the matrix and get some other information from the > following text files: > > file1: > -O- > 1 2 3 4 5 6 > 1 C6.617775 -0.405794 0.371689