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] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Sean Perry
Liam Clarke wrote: 4) WHAT IS WITH THE STUPID SYMBOLS EVERYWHERE LARRY??!! I'm not referring to the $ & @, I can see how they could be useful, although with a list - @dude = (1, 2, 3), to obtain the 2nd value I would expect $d = @dude[1], not $d = $dude[1], that's counterintuitive also. (I am a

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] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Danny Yoo
On Thu, 3 Feb 2005, Liam Clarke wrote: > Had the *ahem* joy of learning Perl last night. Egad. Wrote the script > in Python to get it right, and then 'translated' it to Perl. Hi Liam, I strongly recommend sending the Perl code to that Perl-beginners mailing list referenced earlier. I'm sur

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Max Noel
On Feb 3, 2005, at 00:42, Liam Clarke wrote: I don't find it that bad. Ruby does it as well, and it's perfectly readable. It's more or less equivalent as if condition: and if(condition): both being valid in Python. Yeah, but you'd never call a function foo like this- x = foo in Python. It's just g

Re: [Tutor] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Danny Yoo
> > Ah! Check to see if there's a "sets.py" program somewhere in your > > current working directory. It's very likely that Python is picking > > that up, instead of the 'sets' standard library module. > > You're a genius! That's exactly what I'd done. Hi Glen, I'd attribute it not to genius,

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread lumbricus
Hello! > Actually IIRC Perl *invented* regexes as we know them. The "standard" > regex syntax is known as "Perl regex syntax". Regex are way older than Perl. The roots are in the Fourties(!). They were first used in the editor qed, then ed, then sed and eventually grep. Then awk, emacs, v

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Liam Clarke
> I don't find it that bad. Ruby does it as well, and it's perfectly readable. It's more or less equivalent as if condition: and if(condition): both being valid in Python. Yeah, but you'd never call a function foo like this- x = foo in Python. It's just good to be able to say that a function a

Re: [Tutor] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Glen
On Wed, 2005-02-02 at 22:02, Danny Yoo wrote: > On Wed, 2 Feb 2005, Glen wrote: > > > [EMAIL PROTECTED] glen]$ idle > > set([34, 36, 38, 39]) > > Failed to load extension 'CodeContext' > > Traceback (most recent call last): > > File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 737, i

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Max Noel
(damn, forgot to add the main part of my argumentation) I learnt Perl as well, a few years ago. It was the first scripting language I came across (all I knew before that were C, Turbo Pascal, and a few calculator programming languages), so I immediately fell in love with its string manipulation

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Max Noel
On Feb 2, 2005, at 23:18, Liam Clarke wrote: 1) I'll use Perl for the regex stuff from now on, Perl is obviously built for this. Actually IIRC Perl *invented* regexes as we know them. The "standard" regex syntax is known as "Perl regex syntax". 2 ) There's More Than One Way To Do It makes debugg

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Terry Carroll
I got nothing on your Perl rant, but in response to the subject line... http://www.snopes.com/legal/arizona.htm ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

RE: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread John Purser
Glad someone else thinks so. I tried getting into Perl. The rational made perfect sense and I had picked up several languages by then. Tried. Hated it. Bounced off it. It's like reading alphabet soup. IMHO they took what was wrong with Shell scripting, AWK, Sed and a few other languages and

[Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-02 Thread Liam Clarke
Hi, Had the *ahem* joy of learning Perl last night. Egad. Wrote the script in Python to get it right, and then 'translated' it to Perl. Does the style of coding Python engenders suit the Perl environment in anyone's experienc? AFAI can see there is no real 'style' to Perl, apart from white noise

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] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Danny Yoo
On Wed, 2 Feb 2005, Glen wrote: > [EMAIL PROTECTED] glen]$ idle > set([34, 36, 38, 39]) > Failed to load extension 'CodeContext' > Traceback (most recent call last): > File "/usr/local/lib/python2.4/idlelib/EditorWindow.py", line 737, in > load_standard_extensions > self.load_extension(nam

[Tutor] Python 2.4 with Mandrake 10.0 query

2005-02-02 Thread Glen
My setup is Mandrake 10.0 which came with python 2.3 and a standard Python 2.4 build/install. I always start Idle from an icon on my taskbar, when I click the icon, Idle starts after a second but a small rotating timer appears over the taskbar for 30 seconds and then disappears. If I close Idle im

Re: [Tutor] Tkinter questions

2005-02-02 Thread Michael Lange
On Tue, 1 Feb 2005 19:08:41 +0200 Mark Kels <[EMAIL PROTECTED]> wrote: Hi Mark, > Hello, > I got some Tkinter questions that I need the answer for to complete a > little project of mine: > 1. How can I make the program to open in a X*Y sized window ? from Tkinter import * root = Tk() root.geomet

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Pierre Barbier de Reuille
Even better : import numarray m = numarray.arange(16,shape=(4,4)) numarray.sum(m) array([24, 28, 32, 36]) numarray.sum(axis=1) array([ 6, 22, 38, 54]) Pierre Kent Johnson a écrit : Kent Johnson wrote: Liam Clarke wrote: There's a specific package for arrays http://www.stsci.edu/resources/software_h

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
Kent Johnson wrote: Liam Clarke wrote: There's a specific package for arrays http://www.stsci.edu/resources/software_hardware/numarray that implements array mathematics. I use it for pixel map manipulation in pygame, so it's relatively fast. Here is one way to do what you want using numarray: Here

Re: [Tutor] how to separate hexadecimal

2005-02-02 Thread Max Noel
On Feb 2, 2005, at 10:19, Ewald Ertl wrote: Hi! Using binary operations: a='0x87BE' str(hex(int(a,16) & 0xFF)) '0xbe' str(hex((int(a,16) & 0xFF00) / 0xFF)) '0x87' HTH Ewald Actually, the int conversions aren't even necessary. >>> hex(0x87BE & 0xFF) '0xbe' >>> hex((0x87BE & 0xFF00) / 0xFF) '0x8

Re: [Tutor] How to sum rows and columns of a matrix?

2005-02-02 Thread Kent Johnson
Liam Clarke wrote: There's a specific package for arrays http://www.stsci.edu/resources/software_hardware/numarray that implements array mathematics. I use it for pixel map manipulation in pygame, so it's relatively fast. Here is one way to do what you want using numarray: >>> import numarray Cr

Re: [Tutor] how to separate hexadecimal

2005-02-02 Thread Ewald Ertl
Hi! Using binary operations: >>> a='0x87BE' >>> str(hex(int(a,16) & 0xFF)) '0xbe' >>> str(hex((int(a,16) & 0xFF00) / 0xFF)) '0x87' >>> HTH Ewald on Wed, 2 Feb 2005 15:10:36 +0800 jrlen balane <[EMAIL PROTECTED]> wrote : ---

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] Presentation

2005-02-02 Thread Liam Clarke
Hi Danny, I think that learning Python naturally leads to learning programming. It's like learning to fly, you learn to fly in a Cessna or Piper Cherokee. Simple, elegant, easy to operate. You can then focus on the art of flying, not on how exactly you lower the flaps. Then, once you're good at f

Re: [Tutor] Re: how to separate hexadecimal

2005-02-02 Thread Alan Gauld
> >>> hexa = '0x87BE' > >>> upper = int(hexa[2:4], 16) > >>> lower = int(hexa[4:6], 16) FWIW : You don't need to strip the '0x' from the front, int() is smart enough to do that automatically for base 16 conversions... Alan G. ___ Tutor maillist -

Re: [Tutor] Presentation

2005-02-02 Thread Danny Yoo
> The community is one of the things I particularly like about Python. I > always hated asking a question in the Perl newsgroups; although you > usually got an answer, you were almost certain to be told you're stupid > for not already knowing it. Hi Terry, Just to act as Devil's advocate: the

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] Classes

2005-02-02 Thread Alan Gauld
> I was just wondering, what magic can you do with classes? You can define your own types. Thats what classes are for. Those types can be as 'magic' as your imagination (and programming skills!) allow. > other classes are interesting to subclass? I've seen Object too, but I > don't understand wha

[Tutor] Re: how to separate hexadecimal

2005-02-02 Thread Wolfram Kraus
jrlen balane wrote: i have a 4 digit hex number (2 bytes) and i want to separate it into 2 digit hex (1 byte each) meaning i want to get the upper byte and the lower byte since i am going to add this two. how am i going to do this? should i treat it just like a normal string? please help, thanks. e