Re: [Tutor] What exactly is [::-1]?

2007-07-25 Thread John Fouhy
On 26/07/07, Luke Paireepinart <[EMAIL PROTECTED]> wrote: > Wow, it was actually quite a bit harder to Google than I thought :) > well, some experimentation leads me to believe this is the syntax for > list slicing: [...] It's in the docs, albeit rather tersely: http://www.python.org/doc/current/l

Re: [Tutor] What exactly is [::-1]?

2007-07-25 Thread wesley chun
when you use the 3rd element, it's called the extended slice syntax. here are a few more examples: >>> x = 'python programming' >>> x[::-1] 'gnimmargorp nohtyp' >>> x[2:12:2] 'to rg' >>> ironically, this feature has been available in the interpreter for many years, but it wasn't until circa 2.3 t

Re: [Tutor] What exactly is [::-1]?

2007-07-25 Thread Luke Paireepinart
Dick Moores wrote: > At 08:38 PM 7/25/2007, Luke Paireepinart wrote: >> > I would like to know what exactly the index notation of [::-1] is, >> where >> > it comes from and if there are other variants. >> > >> This is called list slicing. Look into it to figure out what all this >> stuff means. >

Re: [Tutor] What exactly is [::-1]?

2007-07-25 Thread Dick Moores
At 08:38 PM 7/25/2007, Luke Paireepinart wrote: > > I would like to know what exactly the index notation of [::-1] is, where > > it comes from and if there are other variants. > > >This is called list slicing. Look into it to figure out what all this >stuff means. >I could send you a link but I'd

Re: [Tutor] Livewires questions

2007-07-25 Thread Luke Paireepinart
As promised, here's some comments on your code. from livewires import * begin_graphics() allow_moveables() def place_player(): global player_x global player_y global player_shape player_y = random_between(0,47) player_x = random_between(0,63) player_shape = circle(10*pla

Re: [Tutor] What exactly is [::-1]?

2007-07-25 Thread Luke Paireepinart
cuell wrote: > In order to reverse the order of an array, I discovered that I'm > supposed to use [::-1]. > I don't know if 'supposed to' is the correct term. You could just as easily get away with using ['a','b','c'].reverse(). However, below you're using 'array' and I'm not sure exacly what

[Tutor] What exactly is [::-1]?

2007-07-25 Thread cuell
In order to reverse the order of an array, I discovered that I'm supposed to use [::-1]. >>> a = array([1., 2., 3.]) >>> a array([ 1., 2., 3.]) >>> a[::-1] array([ 3., 2., 1.]) >>> I would like to know what exactly the index notation of [::-1] is, where it comes from and if there are o

Re: [Tutor] Livewires questions

2007-07-25 Thread Luke Paireepinart
Tonu Mikk wrote: > Thanks for offering to help! I am following the Livewires exercise > (attached file "5-robots.pdf"). I have gotten as far as page 7. > Attached is also my code so far in robotsarecoming-teleport.py. > Question 1. I was checking for collision of a robot and player first > i

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Kent Johnson
Alan Gauld wrote: > "Terry Carroll" <[EMAIL PROTECTED]> wrote > >> if Y in X: > > FWIW I believe that 'in' did only work for single characters up until > version 2.X so your ideas may have been based on experiences with > an earlier Python version. Yes, it changed in Python 2.3. Kent

Re: [Tutor] Livewires Python course

2007-07-25 Thread Luke Paireepinart
Kent Johnson wrote: > Tonu Mikk wrote: > >> I also >> began reading and coding the Livewires course exercises >> (http://www.livewires.org.uk/python/). I have gotten through the first >> 4 exercise, but got stuck with the last one where we build a robot >> game. The Livewires coding exerci

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Alan Gauld
"Terry Carroll" <[EMAIL PROTECTED]> wrote > if Y in X: > > Which is much more elegant/pythonic; but I didn't know you could do > that > with one string over another. For some reason, I had thought Y > would have > to exactly match one iterable element in X (e.g., one element of a > list, >

Re: [Tutor] How to determine if every character in one string is inanother string?

2007-07-25 Thread Terry Carroll
On Tue, 24 Jul 2007, wesley chun wrote: > i don't have any time myself either (getting ready for OSCON talk), > but i'm not sure what terry's OP was about... looking for a > well-written piece of code, a faster-performing snippet, or both? i > think he was just unsatissfied with his 1st attempt.

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Tiger12506
> By the way, this is an important and fundamental subject about > Python. When I teach classes on Python, I always need to explain > Python's execution model, and I always struggle with it. So, > anything you can tell me that would help me teach this will be much > appreciated. > > Dave The way

Re: [Tutor] Livewires Python course

2007-07-25 Thread Kent Johnson
Tonu Mikk wrote: > I also > began reading and coding the Livewires course exercises > (http://www.livewires.org.uk/python/). I have gotten through the first > 4 exercise, but got stuck with the last one where we build a robot > game. The Livewires coding exercise uses modules that can be down

[Tutor] Livewires Python course

2007-07-25 Thread Tonu Mikk
Hello, I am at a very beginning on trying to learn Python. So far I have read first few chapters of Alan Gauld tutorials, and completed all the exercises of Guido van Robot (http://gvr.sourceforge.net/). I also began reading and coding the Livewires course exercises (http://www.livewires.org.

Re: [Tutor] Logging module

2007-07-25 Thread Tiger12506
> I found the problem. It was rather simple actually. I didn't have remote > logging enabled for syslog. Even though I was logging to localhost, for > some reason, it wouldn't work until I gave syslogd a -r at startup. > Thanks localhost is still remote, in that sockets are used to reach it. Th

Re: [Tutor] Text matching and replacing

2007-07-25 Thread Tiger12506
> Cheers for the critique I'll take you points on board .especially > this schoolboy error It's not an error, really. It will work. Just... not intuitive Errors are things that do not work. > One thing to note about the re expression is that the products are not > these were just substitutes

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Bob Gailer
Alan Gauld wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote > > >>> Perl executes differently to Python in that it does a compilation >>> stage before executing. Therefore Perl knows about all the function >>> definitions prior to executing any code. Python compiles modules >>> which it import

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Dave Kuhlman
On Wed, Jul 25, 2007 at 06:21:08PM +0100, Alan Gauld wrote: > > I'm not sure if the undefined name errors come from the compilation > or from the execution - does anyone else. I confess i've never looked > deeply into how Python actually does its complile/execute cycle. > A couple of points that

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Kent Johnson
Alan Gauld wrote: > "Kent Johnson" <[EMAIL PROTECTED]> wrote >> scripts. However this has no bearing on the current thread; for both >> imported modules and executed scripts, a function must be defined >> before >> it can be called. > > Yes, the bearing is in the way that Perl compiles its code.

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Alan Gauld
"Kent Johnson" <[EMAIL PROTECTED]> wrote >> Perl executes differently to Python in that it does a compilation >> stage before executing. Therefore Perl knows about all the function >> definitions prior to executing any code. Python compiles modules >> which it imports >> but not scripts which it

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Bob Gailer
Alan Gauld wrote: > "nibudh" <[EMAIL PROTECTED]> wrote > > >> in perl this works: >> >> #!/usr/bin/env perl >> hello("World"); >> >> sub hello { >>print "Hello ". $_[0] . "\n"; >> } >> > > > Perl executes differently to Python in that it does a compilation > stage > before executing. T

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Kent Johnson
Alan Gauld wrote: > "nibudh" <[EMAIL PROTECTED]> wrote > >> in perl this works: >> >> #!/usr/bin/env perl >> hello("World"); >> >> sub hello { >>print "Hello ". $_[0] . "\n"; >> } > > > Perl executes differently to Python in that it does a compilation > stage > before executing. Therefore P

Re: [Tutor] Logging module

2007-07-25 Thread jay
Thanks for the reply Kent. I found the problem. It was rather simple actually. I didn't have remote logging enabled for syslog. Even though I was logging to localhost, for some reason, it wouldn't work until I gave syslogd a -r at startup. Thanks jay On 7/25/07, Kent Johnson <[EMAIL PROTECTE

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Alan Gauld
"nibudh" <[EMAIL PROTECTED]> wrote > in perl this works: > > #!/usr/bin/env perl > hello("World"); > > sub hello { >print "Hello ". $_[0] . "\n"; > } Perl executes differently to Python in that it does a compilation stage before executing. Therefore Perl knows about all the function defini

Re: [Tutor] comparing lists, __lt__ and __gt__

2007-07-25 Thread Kent Johnson
Andrew Purdea wrote: > Hello! > I can see that lists have implemented these methods in jython.. > But i can not find any documentation on this. It looks like python > compares each element, and and when it finds a difference, it returns. > Where can i find documenation on this? Will this be

Re: [Tutor] comparing lists, __lt__ and __gt__

2007-07-25 Thread Bob Gailer
Andrew Purdea wrote: > Hello! > I can see that lists have implemented these methods in jython.. > But i can not find any documentation on this. It looks like python > compares each element, and and when it finds a difference, it returns. > Where can i find documenation on this? In python 2.

Re: [Tutor] location of points in a covariance matrix

2007-07-25 Thread Bob Gailer
Beanan O Loughlin wrote: > Hi all, I'm a meteorology postgrad working with python for the first time. > > I have found the location minimum in a large covariance matrix. this > value corresponds to the covariance of two points on a latitude, > longitude grid. > > I need to find a method to locate

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread nibudh
Hi Kent and Alan, Thanks for the responses. It really got me thinking! To test what i thought i knew, i wrote a "hello world" script in perl and python. in perl this works: #!/usr/bin/env perl hello("World"); sub hello { print "Hello ". $_[0] . "\n"; } but in python: #!/usr/bin/env pytho

Re: [Tutor] Text matching and replacing

2007-07-25 Thread Gardner, Dean
Cheers for the critique I'll take you points on board .especially this schoolboy error def findTestDirectories(path): os.chdir(path) directory_listing = os.listdir(os.getcwd()) -- Change this to directory_listing = os.listdir(path) Why look up the current directory

Re: [Tutor] Logging module

2007-07-25 Thread Kent Johnson
jay wrote: > Hello, > > I'm trying to setup simple Syslog logging in python using the logging > module. I would like to use a config file, but so far haven't been able > to get the correct configuration. Actually, I don't get any warnings or > errors, program runs fine, but nothing is logged

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Kent Johnson
Alan Gauld wrote: > "nibudh" <[EMAIL PROTECTED]> wrote > >> I looked over my code (all 41 lines!) and couldn't find anything, >> then on a >> hunch i moved the def statement _above_ the rest of my code and hey >> presto >> it worked. >> >> I vaguely understand why this is happening, but can some

[Tutor] comparing lists, __lt__ and __gt__

2007-07-25 Thread Andrew Purdea
Hello! I can see that lists have implemented these methods in jython.. But i can not find any documentation on this. It looks like python compares each element, and and when it finds a difference, it returns. Where can i find documenation on this? Will this behaviour remain in python for futur

Re: [Tutor] function declaration problems perhaps?

2007-07-25 Thread Alan Gauld
"nibudh" <[EMAIL PROTECTED]> wrote > I looked over my code (all 41 lines!) and couldn't find anything, > then on a > hunch i moved the def statement _above_ the rest of my code and hey > presto > it worked. > > I vaguely understand why this is happening, but can someone explain > it to > me.

[Tutor] function declaration problems perhaps?

2007-07-25 Thread nibudh
Hi list, I've just been writing a small script to parse some xml files and output tab separated values into a separate file. I was surprised to see that my function "processXML(fpart)" was failing with an error along the lines of "processXML not defined" I looked over my code (all 41 lines!) an