Re: [Tutor] Pattern for using multiple windows in Tkinter

2010-05-03 Thread The Green Tea Leaf
OK, thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Pattern for using multiple windows in Tkinter

2010-05-03 Thread Alan Gauld
"The Green Tea Leaf" wrote I've just started to play with Tkinter and can't really figure out the typical pattern of creating an app with several windows - I tried to find some resources on the web but failed to find how to do this. Here is an attempt to explain using code class MyWindowClass:

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread python
> Agreed that > > line = line[:line.index('%')] > > is slightly more readable than > >line = line.split('%', 1)[0] How about: line = line.partition('%')[0] partition() works even if '%' isn't present. The index() and split() techniques raise exceptions if '%' isn't present. Malcolm __

[Tutor] Pattern for using multiple windows in Tkinter

2010-05-03 Thread The Green Tea Leaf
I've just started to play with Tkinter and can't really figure out the typical pattern of creating an app with several windows - I tried to find some resources on the web but failed to find how to do this. Here is an attempt to explain using code class MyWindowClass: def __init__(self): self

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread spir ☣
On Mon, 03 May 2010 13:08:18 +0200 Stefan Behnel wrote: > > Why aren't strings mutable, or lists immutable? > > What would be the use case of an immutable list, as opposed to a tuple? How > would you use mutable strings in a dictionary? [I'm not totally sure of the following, take it with so

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Steven D'Aprano
On Mon, 3 May 2010 08:18:41 pm Luke Paireepinart wrote: > On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel wrote: > > Luke Paireepinart, 03.05.2010 10:27: > >> What's this bizarre syntax? > > > > Look it up in the docs, it's called "with statement". Its purpose > > here is to make sure the file is c

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Stefan Behnel
Luke Paireepinart, 03.05.2010 12:18: On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel wrote: Luke Paireepinart, 03.05.2010 10:27: I thought they changed for loop interations so that if you did for line in open('packages.txt'): etc... it would automatically close the file handle after th

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
2010/5/3 spir ☣ : > On Mon, 03 May 2010 10:55:11 +0200 > Stefan Behnel wrote: > >> Luke Paireepinart, 03.05.2010 10:27: >> > On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote: >> >>                 line = line.split('%', 1)[0] >> > >> > lines = [line[:line.index('%')] for line in ... >> >> Agree

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Steven D'Aprano
On Mon, 3 May 2010 05:35:52 pm Andre Engels wrote: > Don't change the list that you are iterating over. As you have found, > it leads to (to most) unexpected results. Or if you absolutely have to change the list in place, iterate over it *backwards* (starting at the end, and moving towards the

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread spir ☣
On Mon, 03 May 2010 10:55:11 +0200 Stefan Behnel wrote: > Luke Paireepinart, 03.05.2010 10:27: > > On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote: > >> line = line.split('%', 1)[0] > > > > lines = [line[:line.index('%')] for line in ... > > Agreed that > > line = line[

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
On Mon, May 3, 2010 at 3:50 AM, Stefan Behnel wrote: > Luke Paireepinart, 03.05.2010 10:27: >> What's this bizarre syntax? > > Look it up in the docs, it's called "with statement". Its purpose here is to > make sure the file is closed after the execution of the statement's body, > regardless of an

Re: [Tutor] python list, right! but concretely?

2010-05-03 Thread spir ☣
On Mon, 3 May 2010 00:58:14 +0100 "Alan Gauld" wrote: > > "spir ☣" wrote > > > ...When writing "size = size + new_allocated" instead of > > "size = new_allocated", It get a growth pattern of: > >0 3 6 9 16 24 33 43 54 66 80 96 114 > > Which is not exactly what is stated in code, but rather

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Stefan Behnel
Luke Paireepinart, 03.05.2010 10:27: On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote: line = line.split('%', 1)[0] lines = [line[:line.index('%')] for line in ... Agreed that line = line[:line.index('%')] is slightly more readable than line = line.split('%', 1)

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Stefan Behnel
Luke Paireepinart, 03.05.2010 10:27: On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote: You are modifying the list during iteration, so the size changes and the iterator gets diverted. Don't remove the line, just skip over it, e.g. def read_package_names(open_text_file): """Read

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Andre Engels
On Mon, May 3, 2010 at 10:19 AM, Luke Paireepinart wrote: > Hmm, why not > lines = [line for line in lines if not line.strip().startswith('%')] I knew I missed something -- André Engels, andreeng...@gmail.com ___ Tutor maillist - Tutor@python.

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
On Mon, May 3, 2010 at 1:49 AM, Stefan Behnel wrote: > > You are modifying the list during iteration, so the size changes and the > iterator gets diverted. Don't remove the line, just skip over it, e.g. > >    def read_package_names(open_text_file): >        """Read lines, strip any comments and r

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Luke Paireepinart
> If that looks a bit clumsy, use a generator expression: > > linesToDelete = [x for x in lines if x.startswith('%')] > for x in linesToDelete: >   lines.remove(x) > > which idiomatically should probably become: > > for x in [y for y in lines if y.startswith('%')]: >   lines.remove(x) > > Hmm, why

Re: [Tutor] Iterating through a list of strings

2010-05-03 Thread Andre Engels
On Mon, May 3, 2010 at 7:16 AM, Thomas C. Hicks wrote: > I am using Python 2.6.4 in Ubuntu.  Since I use Ubuntu (with its every > 6 months updates) and want to learn Python I have been working on a > post-install script that would get my Ubuntu system up and running with > my favorite packages qui