Re: [Tutor] Better structure?

2005-02-03 Thread Alan Gauld
for x in string: if x in chars: string[i] = '' I just have a hangover from other languages, but I really wanted to know how Python handles iteration over a variable which is being changed within the loop itself. Is the for condition evaluated in every loop? Its bad

Re: [Tutor] Better structure?

2005-02-03 Thread Liam Clarke
Alan said - Its bad practice to delete a member in the collection being iterated but Python copes OK if you just change the current item. Yeah, that's very bad. Makes for all sorts of subtle errors. I usually do the iteration as a for i in range(len(someList) type thing, and collect the indexes

Re: [Tutor] Better structure?

2005-02-03 Thread Jacob S.
Although, (and this will be rough) a list comprehension would be probably do the same thing j=[1, 2,3,4, 5,6,7,8] q = [if not item % 2 for item in j] I really think I've got that 'if not item % 2' wrong, as I can't test it, but I'd be hoping for print q [1, 3, 5, 7] Backwards. ;-) q = [item for

Re: [Tutor] Better structure?

2005-02-02 Thread Alan Gauld
I don't know who's going crazy here... but I checked that straight from the python 2.4 interpreter... Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. a = go on long buddy a.lstrip(gonl) ' on long

Re: [Tutor] Better structure?

2005-02-02 Thread Danny Yoo
On Tue, 1 Feb 2005, Jacob S. wrote: Also why shouldn't string methods include stuff like lstrip which do precisely what I request? Hi Jacob, I think the confusion here is that, in Python, strings can be considered a concrete single thing, but they can also be considered an ordered

Re: [Tutor] Better structure?

2005-02-02 Thread Alan Gauld
Jacob, Writing library code is a difficult and unrewarding task - I've been there so I sympathise, however... So, how would one go about this in a non broken code way? Don't they have something like what I'm requesting. Its not broken, its just different to what you want. What you want is

Re: [Tutor] Better structure?

2005-02-02 Thread Kent Johnson
I would at least introduce some functions. For example each case of your command handling loop could be broken out into a separate function. If there is a lot of shared state between the functions then make them all class methods and put the shared state in the class. Maybe all the drawing

Re: [Tutor] Better structure?

2005-02-02 Thread Jacob S.
Interesting topic. Jacob, Writing library code is a difficult and unrewarding task - I've been there so I sympathise, however... I wouldn't say that... So, how would one go about this in a non broken code way? Don't they have something like what I'm requesting. Its not broken, its just different

Re: [Tutor] Better structure?

2005-02-02 Thread Kent Johnson
Jacob S. wrote: Try writing the code to do what lstrip actually does - its much harder. So the library includes the more difficult function and lets you code the easy ones. def lstrip(string,chars=' ') string = list(string) t = 0 for x in string: if x in chars:

Re: [Tutor] Better structure?

2005-02-02 Thread Sandip Bhattacharya
for x in string: if x in chars: string[i] = '' I just have a hangover from other languages, but I really wanted to know how Python handles iteration over a variable which is being changed within the loop itself. Is the for condition evaluated in every loop? - Sandip

Re: [Tutor] Better structure?

2005-02-02 Thread Orri Ganel
Sandip Bhattacharya wrote: for x in string: if x in chars: string[i] = '' I just have a hangover from other languages, but I really wanted to know how Python handles iteration over a variable which is being changed within the loop itself. Is the for condition evaluated in

Re: [Tutor] Better structure?

2005-02-01 Thread Kent Johnson
Danny Yoo wrote: On Mon, 31 Jan 2005, Jacob S. wrote: ### Pseudocode commandDispatchTable = {'clear' : clearCommand 'quit' : quitCommand 'remove' : removeCommand 'return' : returnCommand 'gatl'

Re: [Tutor] Better structure?

2005-02-01 Thread Liam Clarke
http://www.cs.bell-labs.com/cm/cs/pearls/ That link seems to be dead. Pity. My whole programming experience is comprised of Ah-Ha's followed by Um's... -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to

Re: [Tutor] Better structure?

2005-02-01 Thread Alan Gauld
What, like global radiusaxis, radiusaxis2 exactly. And since there is no input parameter and no return statement and you only call start() once... Not true. If y == 'clear', then start is called to redraw the window. Very important part. OK, I missed that, but its still better to hide

Re: [Tutor] Better structure?

2005-02-01 Thread Alan Gauld
ever get the chance, you may want to take a look at a book called Programming Pearls: http://www.cs.bell-labs.com/cm/cs/pearls/ I'll second that. Personally I try to read both books (I have the original 2 volume version!) every couple of years - they are that valuable. Most newbie

Re: [Tutor] Better structure?

2005-02-01 Thread Jacob S.
So, how would one go about this in a non broken code way? Don't they have something like what I'm requesting. It seems to me that a few things are flawed in the standard distribution. Little things like the overlooking of adding a method or function to decimal for returning an instance with x

Re: [Tutor] Better structure?

2005-02-01 Thread Jeff Shannon
Jacob S. wrote: So, how would one go about this in a non broken code way? Don't they have something like what I'm requesting. No, but it's pretty easy to do: def exact_lstrip(astring, stripstring): if astring.startswith(stripstring): astring = astring[len(stripstring):] return

Re: [Tutor] Better structure?

2005-01-31 Thread Alan Gauld
def start(): lots of lines... global xaxis global yaxis Its traditional to put global statements at the top of the function. Also you only need one line to list all of the global variables global radiusaxis global radiusaxis2 Similarly here., and again you can

Re: [Tutor] Better structure?

2005-01-31 Thread Danny Yoo
On Mon, 31 Jan 2005, Jacob S. wrote: I think this thing is screaming for better structure, but previous attempts at using oop for it have failed. Hi Jacob, Ok, I see one big refactoring that should help things quite a bit. There's a large case-analysis off if/elif/elif statements that