Re: [Tutor] Better structure?

2005-02-04 Thread Alan Gauld
> 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 think you mean: q = [ item for item in j if item % 2] item % 2 will return zero = false on even numbers, so your test is true for od

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 it

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 indexe

Re: [Tutor] Better structure?

2005-02-03 Thread Jacob S.
You can also iterate over a copy of the list and change the original. i.e. a = range(10) for x in a[:]: if x % 2 == 0: a.remove(x) print a And yes, I did test it this time. Jacob >for x in string: >if x in chars: >string[i] = '' I just have a hangover from other

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 loo

Re: [Tutor] Better structure?

2005-02-03 Thread Alan Gauld
> > 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 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-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
Orri Ganel wrote: Kent Johnson wrote: 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:

Re: [Tutor] Better structure?

2005-02-02 Thread Orri Ganel
Kent Johnson wrote: 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 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: string.re

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 to

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 comman

Re: [Tutor] Better structure?

2005-02-02 Thread Liam Clarke
Hello all, > > So, how would one go about this in a non broken code way? Don't they > have > > something like what I'm requesting. If not,it's a challenge you can implement yourself! Ever use QBasic? Had a command - a$ = inkey$(1) Which would return a key press as a$. Very handy for 'press a

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 mu

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 collect

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.l

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 astr

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 pl

Re: [Tutor] Better structure?

2005-02-01 Thread Jeff Shannon
Jacob S. wrote: I don't know who's going crazy here... but I checked that straight from the python 2.4 interpreter... >>> a = "go on long buddy" >>> a.lstrip('gonl') ' on long buddy' >>> a.lstrip('gonl ') 'buddy' >>> Note that in the second case, I've included a space in the lstrip() parameter.

Re: [Tutor] Better structure?

2005-02-01 Thread Jacob S.
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 lo

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 newbi

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 bette

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 tak

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 Danny Yoo
On Mon, 31 Jan 2005, Jacob S. wrote: > BTW, it was a few months ago, not days... but the thought still counts. > At least you remember. Hi Jacob, Wait, was it really a few months ago? Let me check the archive... http://mail.python.org/pipermail/tutor/2004-December/033728.html You're ri

Re: [Tutor] Better structure?

2005-01-31 Thread Jacob S.
Ah, I like. BTW, it was a few months ago, not days... but the thought still counts. At least you remember. I was getting stumped by the difference in comparing y The check for seeing what the first word is made me slamp my forehead... Thanks! Jacob Schmidt On Mon, 31 Jan 2005, Jacob S. wrote: I

Re: [Tutor] Better structure?

2005-01-31 Thread Jacob S.
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 What, like global radiusaxis, radiusaxis2 Simil

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 in

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 ca

[Tutor] Better structure?

2005-01-31 Thread Jacob S.
I think this thing is screaming for better structure, but previous attempts at using oop for it have failed. I think Derintegral is okay, I'm focusing on FunctionGrapher5.py--but you can comment on both. (To Johan Nilsson: I haven't had time to implement Simpson's rule instead of Reimann's sum y