Re: [Tutor] working with new classes

2005-03-09 Thread Sean Perry
C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) print l#same a

Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
Sean Perry wrote: C Smith wrote: ### class Ring(list): def __init__(self, l): self[:] = l self._zero = 0 def turn(self, incr=1): self._zero+=incr def __getitem__(self, i): return self[(i-self._zero)%len(self)] l=Ring(range(10)) print l l.turn(5) pr

Re: [Tutor] getting a webpage via python

2005-03-09 Thread Kent Johnson
Kent Johnson wrote: Paul Tremblay wrote: So I just make a file called /etc/router_passwords and include something like WRT54G username password Then parse the file, and supply the info to the password handler? This is easy to do, and I guess it is secure. The book "Foundations of Python Network P

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Dave S
Danny Yoo wrote: [Windows bashing cut] Python's support for Windows stuff is actually quite good, thanks to the work of Mark Hammond: http://starship.python.net/crew/mhammond/ A lot of us here do use Windows for COM programming. Let's get back to talking about Python programming and let's help

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Bill Mill
Dave, > >>> > >>> > >>> import os.path > >>> print os.path.expanduser('~/memo.txt') > C:\Documents and Settings\Administrator/memo.txt > >>> f = open(os.path.expanduser('~/memo.txt')) > Traceback (most recent call last): > File "", line 1, in ? > f = open(os.path.expanduser('~/memo.txt')) > I

Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
I'm having some strange results using the "or" operator. In every test I do I'm matching both sides of the "|" metacharacter, not one or the other as all documentation says it should be (the parser supposedly scans left to right, using the first match it finds and ignoring the rest). It should

Re: [Tutor] regular expression question

2005-03-09 Thread Liam Clarke
Hi Mike, Do you get the same results for a search pattern of 'A|B'? On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall <[EMAIL PROTECTED]> wrote: > I'm having some strange results using the "or" operator. In every test > I do I'm matching both sides of the "|" metacharacter, not one or the > other a

Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
Indeed I do: >>> import re >>> x = re.compile('A|B') >>> s = " Q A R B C" >>> r = x.sub("13", s) >>> print r Q 13 R 13 C On Mar 9, 2005, at 12:09 PM, Liam Clarke wrote: Hi Mike, Do you get the same results for a search pattern of 'A|B'? On Wed, 9 Mar 2005 11:11:57 -0800, Mike Hall <[EMAIL PROTECT

Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
But I only want to ignore "B" if "A" is a match. If "A" is not a match, I'd like it to advance on to "B". On Mar 9, 2005, at 12:07 PM, Marcos Mendonça wrote: Hi Not and regexp expert. But it seems to me that if you want to ignora "B" then it should be (A) | (^B) Hope it helps! On Wed, 9 Mar 2005

Re: [Tutor] regular expression question

2005-03-09 Thread Liam Clarke
Actually, you should get that anyway... """ | Alternation, or the ``or'' operator. If A and B are regular expressions, A|B will match any string that matches either "A" or "B". | has very low precedence in order to make it work reasonably when you're alternating multi-character strings. Crow|S

Re: [Tutor] regular expression question

2005-03-09 Thread Liam Clarke
Oops I mean for i in range(len(k)): i f k[i] == 'A' or k[i]=='B': k[i ]= 13 On Thu, 10 Mar 2005 09:28:59 +1300, Liam Clarke <[EMAIL PROTECTED]> wrote: > Actually, you should get that anyway... > > """ > | > Alternation, or the ``or'' operator. If A and B are regular > express

Re: [Tutor] regular expression question

2005-03-09 Thread Mike Hall
but yeah, it seems you're expecting it to examine the string as a whole. I guess I was, good point. On Mar 9, 2005, at 12:28 PM, Liam Clarke wrote: Actually, you should get that anyway... """ | Alternation, or the ``or'' operator. If A and B are regular expressions, A|B will match any string t

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread jfouhy
> > >>> > > >>> > > >>> import os.path > > >>> print os.path.expanduser('~/memo.txt') > > C:\Documents and Settings\Administrator/memo.txt > > >>> f = open(os.path.expanduser('~/memo.txt')) > > Traceback (most recent call last): > > File "", line 1, in ? > > f = open(os.path.expanduser('~/memo.txt'

Re: [Tutor] getting a webpage via python

2005-03-09 Thread Paul Tremblay
On Wed, Mar 09, 2005 at 08:29:46AM -0500, Kent Johnson wrote: > > Kent Johnson wrote: > >Paul Tremblay wrote: > > > >>So I just make a file called /etc/router_passwords and include > >>something like > >>WRT54G username password > >> > >>Then parse the file, and supply the info to the password ha

Re: [Tutor] regular expression question

2005-03-09 Thread Kent Johnson
Mike Hall wrote: A simple example will show what I mean: >>> import re >>> x = re.compile(r"(A) | (B)") >>> s = "X R A Y B E" >>> r = x.sub("13", s) >>> print r X R 13Y13 E ...so unless I'm understanding it wrong, "B" is supposed to be ignored if "A" is matched, yet I get both matched. I get

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Dave S
[EMAIL PROTECTED] wrote: import os.path print os.path.expanduser('~/memo.txt') C:\Documents and Settings\Administrator/memo.txt f = open(os.path.expanduser('~/memo.txt')) Traceback (most recent call last): File "", line 1, in ? f = open(os.path.expanduser('~/memo.tx

Re: [Tutor] working with new classes

2005-03-09 Thread C Smith
Thanks to Sean and Kent for replies. I found a site that provided some good examples, too, at http://www.cafepy.com/articles/python_attributes_and_methods/ ch03s02.html Here's a blurb from the title page: wep page excerpt Shalabh Chaturvedi Copyright © 2004 Shalabh Chaturvedi This book

Re: [Tutor] working with new classes

2005-03-09 Thread Kent Johnson
C Smith wrote: Alternatively, the list class can be appended with helpers like 'turn' and 'segment' which can actually turn the "ring" and remove a piece from it without worrying about the endpoint: ### >>> class ring(list): def turn(self, incr=1): incr%=len(self) self[:]

Re: [Tutor] Acessing files in Windows 2000

2005-03-09 Thread Bill Mill
> mmm ... I kind of see what you mean. > > Does anyone have like a realy large shovel so I can dig a hole and hide ? No worries, we've all been there before. Sometimes you just can't see what's right in front of your face. Don't let it stop you, or stop you from asking questions. Peace Bill Mil